使用ulong*参数从c#中的dll导入函数
我在visual studio 2015中使用windows 7和c#进行开发; 在我的其他c程序中导入dll中使用的函数时出现问题:使用ulong*参数从c#中的dll导入函数,c#,windows,dll,pinvoke,dllimport,C#,Windows,Dll,Pinvoke,Dllimport,我在visual studio 2015中使用windows 7和c#进行开发; 在我的其他c程序中导入dll中使用的函数时出现问题: unsigned long ulaVersion[2]; MHM_GetDLLVersion(ulaVersion); cout << "MHM_1SL_interface.dll Version: " << ulaVersion[1] << "." << ulaVersion[0] << endl &
unsigned long ulaVersion[2];
MHM_GetDLLVersion(ulaVersion);
cout << "MHM_1SL_interface.dll Version: " << ulaVersion[1] << "." << ulaVersion[0] << endl << endl;
该函数可以工作并打印1.8
现在我试着用c#
我试图使用这个,但我收到了“8”的结果。。。
我错在哪里?
哪种方法可以将ulong*参数传递给c#?中的函数?它是一个数组,因此参数必须是UInt32[],无ref。请确保传递一个已经足够大且包含2个元素的参数。长的64位不是吗?如果是这样的话,那么您可能需要将UInt32换成UInt64@brandonstrong不是在Windows上的C++。这里的
long
是32位。@Hans Passant当然可以。..ThanksIt是一个数组,所以参数必须是UInt32[],没有ref。一定要传递一个已经足够大且包含2个元素的参数。长的64位不是吗?如果是这样的话,那么您可能需要将UInt32换成UInt64@brandonstrong不是在Windows上的C++。这里的long
是32位。@Hans Passant当然可以了。谢谢
unsigned long __stdcall MHM_GetDLLVersion(unsigned long *pulDllVersion);
[DllImport(@"MHM_1SL_interface.dll", CallingConvention = CallingConvention.StdCall)]
public static extern UInt32 MHM_GetDLLVersion(ref UInt32 ulaVersion);