Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我是否正确调用这个C++ DLL? 我需要调用C++中的C++ DLL函数,C++函数定义为 DWORD Init(char*[],int,int,int);_C#_Dll_Types_Dllimport - Fatal编程技术网

C# 我是否正确调用这个C++ DLL? 我需要调用C++中的C++ DLL函数,C++函数定义为 DWORD Init(char*[],int,int,int);

C# 我是否正确调用这个C++ DLL? 我需要调用C++中的C++ DLL函数,C++函数定义为 DWORD Init(char*[],int,int,int);,c#,dll,types,dllimport,C#,Dll,Types,Dllimport,我把它叫做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] = "12

我把它叫做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代替dWord是可以的,但是如果我是正确的,请告诉我。 谢谢


<>编辑-I应该添加,我在C++应用程序中测试了DLL,它工作正常。如果你试图把32位DLL加载到一个64位进程中,反之亦然,则P>BadiaMaFrimeExtExchange经常发生。如果DLLTest.dll是32位dll,则需要编译x86平台的C dll,而不是任何CPU


如果您尝试将32位DLL加载到64位进程中,或将32位DLL加载到64位进程中,则通常会发生BadImageFormatException。如果DLLTest.dll是32位dll,则需要编译x86平台的C dll,而不是任何CPU