문제

Function description here.

I'm struggling to get it right to call this function from c#. I'm at a stage where I'm calling it but it's returning E_INVALIDARG.

I've set it up as follows...

[DllImport("p2p.dll", CharSet=CharSet.Unicode)]
internal static extern uint PeerGroupCreateInvitation(IntPtr hGroup, string pwzIdentityInfo, IntPtr pftExpiration, int cRoles, IntPtr pRoles, out string ppwzInvitation);

My best guess is the 5th parameter, "pRoles". I'm supposed to send it a pointer to one or two GUIDs representing the role type.

PEER_GROUP_ROLE_ADMIN
PEER_GROUP_ROLE_MEMBER

I have no clue presently how to do this from c#.

In C this parameter looks like this when calling the function...

..., (PEER_ROLE_ID*) &PEER_GROUP_ROLE_MEMBER, ...

PEER_ROLE_ID looks like a System.Guid type. PEER_GROUP_ROLE_MEMBER looks like the actual GUID. (Can I get this from the p2p.dll file?)

Any help would be greatly appreciated... especially since there's close to ZERO info on this function on the internet.

Working solution after everyone's comments.

Declaration:

[DllImport("p2p.dll")]
public static extern uint PeerGroupCreateInvitation(IntPtr hGroup, [MarshalAs(UnmanagedType.BStr)] string pwzIdentityInfo, int pftExpiration, int cRoles, ref Guid pRoles, out IntPtr ppwzInvitation);

Calling:

uint hr = PeerGroupCreateInvitation(hGroup, identityInfo, 0, 1, ref PEER_GROUP_ROLE_MEMBER, out pInvitation);

...where PEER_GROUP_ROLE_MEMBER is the System.Guid for this role.

Getting the invitation:

string invitation = Marshal.PtrToStringAuto(pInvitation);
도움이 되었습니까?

해결책

This is the correct declaration:

[DllImport("p2p.dll")] 
public static extern uint PeerGroupCreateInvitation( 
                IntPtr hGroup,  /* Updated with @RedDude's suggestion */
                [MarshalAs(UnmanagedType.BStr)] string pwzIdentityInfo, 
                int pftExpiration, // 32 bit, not 64 bit 
                int cRoles, 
                ref Guid pRoles, 
                out IntPtr ppwzInvitation); 

다른 팁

As @strenr has said you should use a ref Guid argument to pass the GUID for the pRoles. However, and you might have already decided against this, have you taken a look at the WCF peer-to-peer support? This would give you most of the peer-to-peer capabilities already wrapped up in a .NET interface?

Take a look here

http://msdn.microsoft.com/en-us/library/system.net.peertopeer.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top