Enumerating People near me in Microsoft Windows Vista Beta 1




Now that we have learned how to Sign in, we can see who else is signed in


 


HRESULT WINAPI PeerCollabEnumEndpointsNearMe(


HPEERENUM* phPeerEnum
);

(this seems to be missing from the MSDN documentation! Bug filed!)


 


 


This returns a PeerEnumeration handle on which you can call


 


HRESULT WINAPI PeerGetItemCount(
HPEERENUM
hPeerEnum,
PULONG
pCount
);


http://windowssdk.msdn.microsoft.com/library/en-us/P2PSDK/p2p/peergetitemcount.asp


 


 


To get the number of endpoints available


 


Or


 


HRESULT WINAPI PeerEndEnumeration(
HPEERENUM
hPeerEnum
);


http://windowssdk.msdn.microsoft.com/library/en-us/P2PSDK/p2p/peergetnextitem.asp


 


To end the enumeration once you are done with it.


 


Or, the most interesting thing you can do to an enumeration handle is get the stuff from the enumeration!


 


HRESULT WINAPI PeerGetNextItem(
HPEERENUM
hPeerEnum,
PULONG
pCount,
PVOID*
ppvItems
);
http://windowssdk.msdn.microsoft.com/library/en-us/P2PSDK/p2p/peergetnextitem.asp


 


Note that this api returns memory that you have to free with


VOID WINAPI PeerFreeData(
PVOID
pvData
);


http://windowssdk.msdn.microsoft.com/library/en-us/P2PSDK/p2p/peerfreedata.asp


 


Let’s enumerate some people near me!


 


HRESULT EnumeratePeopleNearMe()


{


HRESULT         hr = S_OK;


HPEERENUM     hEnum;


ULONG            count = 0;


PEER_ENDPOINT_NEAR_ME **ppEndpoints = NULL;


ULONG i;


 


hr = PeerCollabEnumEndpointsNearMe(&hEnum);


if (SUCCEEDED(hr))


{


hr = PeerGetItemCount(hEnum, &count);


if (SUCCEEDED(hr) && count > 0)


{


hr = PeerGetNextItem(hEnum, &count, (void**) &ppEndpoints);


if (SUCCEEDED(hr))


{


for (i = 0; i < count; i++)


{


if (ppEndpoints[i]->pwzFriendlyName != NULL)


{


printf(“Endpoint: %S\n”, ppEndpoints[i]->pwzFriendlyName);


}


else


{


printf(“Endpoint: (no friendly name)\n”);


}


}


PeerFreeData(ppEndpoints);


}


 


}


else


{


printf(“No endpoints”);


}


PeerEndEnumeration(hEnum);


}


return hr;


}


 


int __cdecl main(int argc, __in_ecount(argc) char *argv[])


{


 


HRESULT hr = S_OK;


hr =  PeerCollabStartup(PEER_COLLAB_VERSION);


if (SUCCEEDED(hr))


{


hr = PeerCollabSignin(PEER_PRESENCE_NEAR_ME);


if (SUCCEEDED(hr))


{


hr=EnumeratePeopleNearMe();


}


(void)PeerCollabShutdown();


}


return 0;


}


 


 


Sorry for the repost, for some reason this didnt get published to the external site.


Comments (0)