Unregistering a Peer Name (Windows CE 5.0)

Send Feedback

PNRP uses the WSASetService function to register peer names. To unregister a peer name, configure WSAQUERYSET and call WSASetService by passing RNRSERVICE_DELETE in the essOperation parameter.

The following list identifies important information about unregistering a peer name.

  • Only an application that registers a peer name can unregister it.
  • A peer name is unregistered automatically if WSACleanup is called.
  • PNRP always removes the entire service name registration. It does not allow removal of individual addresses.

To unregister a peer name

  1. Configure a WSAQUERYSET (Windows Sockets) structure.

    The following table shows the values to set.

    Value Description
    dwSize Specifies the size the WSAQUERYSET structure.
    dwNameSpace Must be either NS_PNRPNAME or NS_ALL.
    lpServiceClassID Must be SVCID_PNRPNAME.
    lpszServiceInstanceName Points to the peer name that is being registered.
    lpszContext Must be a valid cloud name, an empty string, or NULL. If this value is NULL or an empty string, the default cloud, "Global_", is used.
    lpBlob Points to a PNRPINFO structure.
    lpcsaBuffer Point to the address list.

    Note   All WSAQUERYSET members that are not specified in the preceding table are reserved and must be set to NULL or zero (0) depending on the data type of the member.

    PNRP uses the BLOB (Windows Sockets) structure to pass data to the WSAQUERYSET structure during calls to several functions. For use with PNRP, BLOB points to either a PNRPINFO structure or a PNRPCLOUDINFO structure.

  2. Call the WSASetService function. The following table shows the parameter values to pass.

    Parameter Description
    essOperation Must have a value of RNRSERVICE_DELETE.
    dwFlags Must be zero (0).
    lpqsRegInfo Must point to WSAQUERYSET that is configured to register a peer name.

The following code example shows how to unregister a peer name by configuring the WSAQUERYSET (Windows Sockets) structure and calling the WSASetService (Windows Sockets) function.

//------------------------------------------------------------------------
// Function: PnrpUnregister
// Purpose:  Unregister the given name from a PNRP cloud
// Arguments:
//  pwzIdentity : identity string originally used to register the name
//  pwzName     : name to unregister from PNRP
//  pwzCloud    : name of the cloud to unregister from, NULL = global cloud
// Returns:  HRESULT
//------------------------------------------------------------------------
HRESULT PnrpUnregister(PWSTR pwzIdentity, PWSTR pwzName, PWSTR pwzCloud)
{
  HRESULT         hr = S_OK;
  PNRPINFO        pnrpInfo = {0};
  BLOB            blPnrpData = {0};
  WSAQUERYSET     querySet = {0};
  INT             iRet;
  // Build the WSAQUERYSET required to unregister.
  pnrpInfo.dwSize = sizeof(pnrpInfo);
  pnrpInfo.dwLifetime = 60 * 60 * 8; // 8 hours
  pnrpInfo.lpwszIdentity = pwzIdentity;

  blPnrpData.cbSize = sizeof(pnrpInfo);
  blPnrpData.pBlobData = (BYTE*)&pnrpInfo;

  querySet.dwSize = sizeof(querySet);
  querySet.dwNameSpace = NS_PNRPNAME;
  querySet.lpServiceClassId = (LPGUID)&SVCID_PNRPNAME;
  querySet.lpszServiceInstanceName = pwzName;
  querySet.lpszContext = pwzCloud;
  querySet.lpBlob = &blPnrpData;

  // Unregister the name with PNRP.
  iRet = WSASetService(&querySet, RNRSERVICE_DELETE, 0);
  if (iRet != 0)
  {
    hr = HRESULT_FROM_WIN32(WSAGetLastError());
  }
  return hr;

}

See Also

Peer-to-Peer Application Development | Registering a Peer Name

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.