如何从c#传递到c ++ .dll
问题描述:
我使用dllimport方法将一个字符串从c#传递给c + + lib dll。
c ++ .dll的方法是: -
I'm using the dllimport method to pass a string from c# to the c++ lib dll. The c++ .dll's method is:-
bool WriteReply(const unsigned char *reply, const unsigned long reply_length);
如何从c#传递它,所以它会接受参数?我试过Intptr,byte []和字符串...没有什么工作,我继续得到 AccessViolationException
错误。
How do I pass it from c# so it will accept the arguments? I've tried Intptr, byte[], and string...nothing works, I keep getting the AccessViolationException
error.
任何想法吗?
谢谢!
Any ideas anyone? Thanks!
答
我认为这会奏效:
[DllImport("dllfile.dll", EntryPoint = "WriteReply")]
private static extern bool
WriteReply(IntPtr reply, System.UInt32 reply_length);