如何从c#传递到c ++ .dll [英] How do I pass from c# to c++ .dll

查看:149
本文介绍了如何从c#传递到c ++ .dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

用于c ++ lib dll的C#wrapper类

我使用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);

这篇关于如何从c#传递到c ++ .dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆