Need c# represenmtation of method signature for C

Announcements and discussion for PInvoke

Need c# represenmtation of method signature for C

Postby chitrarasan » Wed Jul 20, 2011 2:41 pm

I have following method in c
BOOL Register(EnumPID,Enum AppID,const char *pServerID,const char *pDestSN,char *pUnlockCode,char Type,
long Level,long ExpireValue,long Len );

What is the C# method signature for the above c method?
Posts: 1
Joined: Wed Jul 20, 2011 2:29 pm

Postby Brian Donahue » Wed Jul 20, 2011 3:56 pm

PInvoke exists for a good reason, and that reason is that translating unmanaged calls to managed PInvoke calls is difficult and sometimes involves some trial and error. Microsoft have some very general guidelines here but the most important tip is to make sure the length of the datatypes is the same between PInvoke calls and the underlying unmanaged code. If you really have problems, it may be necessary to use the MarshalAs attribute to force the hand of Interop to use the right type.

But as a starting point I'd suggest
Code: Select all
 bool Register(long PID, long AppID, [MarshalAs(UnmanagedType.LPWStr)] string pServerID, [MarshalAs(UnmanagedType.LPWStr)] string pDestSN, [MarshalAs(UnmanagedType.LPWStr)] string pUnlockCode, char Type, long Level, long ExpireValue, long Len)
Brian Donahue
Posts: 6590
Joined: Mon Aug 23, 2004 9:48 am

Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests