问题
I have a dynamic library (.dll) written in C++ exporting a function I'd like to use in my C# applicaiton:
int SendText(void* pControl, char* sText);
How can I, given it takes a pointer to void?
回答1:
for void* you can just use IntPtr ,
strings will work with the MarshalAs attribute:
[DllImport("MyDll.dll", CharSet = CharSet.Ansi)]
public static extern int SendText(IntPtr pControl, [MarshalAs(UnmanagedType.LPStr)] string sText);
来源:https://stackoverflow.com/questions/10630419/how-to-call-from-a-c-sharp-applicaiton-a-c-function-taking-a-pointer-to-void