Moore's Mind

Wednesday, September 28, 2005

Problems Enumerating EndPoints

I'm trying to put together a demo application that uses all the capabilities of the new PeerCollab Managed Wrapper. However, enumerating endpoints for a given contact is giving me problems.

When I call PeerCollabEnumEndpoints passing in what appears to be valid PEER_CONTACT info, I get an E_INVALIDARG result. At first, I was trying to pass in contact info for a PEER_NEAR_ME. Figuring, maybe the contact needs to be added to my list of contacts, I did this, but the same error occurs.

The defintion of PEER_CONTACT works for all the other API calls, so I don't think its the problem.

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct PEER_CONTACT
[MarshalAs(UnmanagedType.LPWStr)] public String pwzPeerName;
[MarshalAs(UnmanagedType.LPWStr)] public String pwzFriendlyName;
public int fWatch;
public int WatcherPermissions;

The API is the following:

HRESULT WINAPI PeerCollabEnumEndpoints(
IN const PCPEER_CONTACT pcContact,
OUT HPEERENUM * phPeerEnum);

My DllImport definition is:

[DllImport("p2p.dll", PreserveSig=true)]
internal static extern uint PeerCollabEnumEndpoints(ref PEER_CONTACT pcContact, ref IntPtr phPeerEnum);

Yet, when I pass the same PEER_CONTACT info to PeerCollabDeleteContact, there is not error.

I'm trying to enumerate the list of endpoints in order to send an invitation.

Any help is appreciated.

Monday, September 26, 2005

Finished Managed PeerCollab Wrapper

I finally finished implementing the last PeerCollab API function.

The whole wrapper is implemented in C# using DllImport's and InteropServices. I've managed to verify that most functions work correctly. Once I've verified all functions work correctly, I'll probably refactor the classes a little bit and create a custom extension to the My namespace.

I believe need a second Windows Vista computer in order to see another contact besides myself and to monitor changes. I'm not sure why if I Sign-In to the Internet, I don't see other contacts. Is there some port I'm supposed to open on my network firewall?

If anyone knows of an easy way to create a second contact using only one computer, that would be helpful.

Saturday, September 24, 2005

PeerGetNextItem Trick

I'm wrapping the PeerCollab SDK using C#/DllImport.

I was struggleing with PeerGetNextItem returning garbage data until I finally realized its was returning an array of pointers.

HRESULT WINAPI PeerGraphGetNextItem(
OUT PVOID * ppvItems);

[DllImport("p2p.dll", PreserveSig=true)]
internal static extern uint PeerGetNextItem(IntPtr hPeerEnum, ref uint count, ref IntPtr ppItems);

To call this function and extract the data, you'll need to do the following...

uint ulItem = 1;
IntPtr capptr = IntPtr.Zero;
uint result = PeerCollabNative.PeerGetNextItem(hPeerEnum, ref ulItem, ref capptr );

The trick is to marshal the first item in the array as a pointer before marshalling the type...

IntPtr itemptr = Marshal.ReadIntPtr(capptr);
PEER_CAPABILITY ncap = (PEER_CAPABILITY)Marshal.PtrToStructure(itemptr, typeof(PEER_CAPABILITY));

Hope this helps someone.

Friday, September 16, 2005

Microsoft Peer-to-Peer Blog Links

The following links are people at Microsoft working on the Peer-to-Peer technology and gave recent talks at Microsoft's PDC 2005:

Ravi Rao's blog

Noah Horton's WebBlog

Tripp Parks's WebLog

Tuesday, September 13, 2005

Peer Collaboration Infrastructure

I've started to investigate the new PeerCollab* methods included in the Windows Vista version of the Platform SDK. So far the documentation isn't really good. The best, but limited source of information is Tripp Parke's blog (

The SDK documentation is confusing. The term's Peer, Peer Application, Contact and Local Peer are used interchangable.

I'm working on a Managed C++ wrapper for the API's to simplify using this functionality from managed code. The problem is, I'm not much of a C++ programmer, so it slow going.

The other thing I've noticed is that after calling the PeerCollabSignIn method, a Collaboration Host icon appears in the system tray. A p2phost.exe appears in the task manager. I'm not sure what the purpose of this is yet.

Hopefully more inforamtion will be released at next weeks PDC. I have lots of ideas for some great peer applications if I can just get the darn API's to work.