[英]Am I calling this C++ DLL correctly?
我需要从C#调用C ++ DLL函数,C ++函数定义是
DWORD Init(char*[],int,int,int);
而我正在用C#这样称呼它
[DllImport("DLLTest.dll")]
unsafe public static extern int Init(string[] detailsarray, int amount, int ID1, int ID2);
//then in main...
string[] details = new string[3];
details[0] = "blahblah";
details[1] = "bloobloo";
details[2] = "1234";
int result = Init(details, 1, 16, 170);
当我运行它时,我得到一个类型为System.BadImageFormatException的未处理异常。 我相信当C ++ DLL期待char *时可以通过字符串,我也认为可以在C#中使用int来代替C ++中的DWORD,但如果我是正确的,请告诉我。
谢谢。
编辑 - 我应该补充一点,我已经在C ++应用程序中测试了DLL,它运行正常。
如果您尝试将32位DLL加载到64位进程中,则通常会发生BadImageFormatException,反之亦然。 如果DLLTest.dll是32位DLL,则需要为x86平台编译C#DLL,而不是任何CPU
http://msdn.microsoft.com/en-us/library/zekwfyz4(v=vs.100).aspx
http://davidstechtips.com/wp-content/uploads/2010/06/VisualStudioPlatformTargetx86.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.