Is this list correct?
unsigned int(c) -> uint(c#) const char*(c) -> String(c#) unsigned int*(c) -> uint[](c#) unsigned char*(c) -> byte[](c#)
I think there’s a mistake here because with these 4 parameters for native function I have PInvokeStackImbalance.
C function is:
bool something
(unsigned char *a,
unsigned int a_length,
unsigned char *b,
unsigned int *b_length);
PInvoke is:
[DllImport(@"lib.dll", EntryPoint = "something")]<br>
public static extern bool something(
byte[] a,
uint a_length,
byte[] b,
uint[] b_length);
First, PInvoke.net is your friend.
Second, You conversions are correct except that you should use a
StringBuilderfor functions that take achar*as a buffer to fill ([in out]).Your stack imbalance may be due to the use of different calling conventions. The default calling convention for C# is
__stdcall, but your C function is probably__cdecl. If that is the case you will need to add the CallingConvention to yourDLLImportattribute.EDIT: Also, as Groo pointed out, if the pointer arguments in your C function are actually just pointers to
unsigned int(for example, as opposed to expecting an array ofint) then you should useref uintinstead of anint[].