Declare the function in C# like this:
[DllImport(@"MyDll.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int func1(
int arg1,
StringBuilder arg2,
out int arg3
);
And then call it like this:
int arg1 = ...;
StringBuilder sb = new StringBuilder(2048);
int arg3;
int retVal = func1(arg1, sb, out arg3);
string arg2 = sb.ToString();
Note that C# IntPtr
does not match C int
. You need C# int
to match that because IntPtr
is the same size as a pointer, either 32 or 64 bits. But int
is always 4 bytes.
I am assuming that your DLL uses the cdecl calling convention. If you are using stdcall, you can make the obvious alteration.
I also assumed that your data is in fact text data. If it is just a plain old byte array then the code is simpler.
[DllImport(@"MyDll.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int func1(
int arg1,
byte[] arg2,
out int arg3
);
And then to call:
int arg1 = ...;
byte[] arg2 = new byte[2048];
int arg3;
int retVal = func1(arg1, arg2, out arg3);