从 C# 调用 x64 C++ DLL,进程挂起(更新)
Calling x64 C++ DLL from C#, process hangs (update)
我正在将托管 C++ DLL (MecDll) 从 x86 移植到 x64。
C# 中的测试代码:
[DllImport("test.dll"), System.Security.SuppressUnmanagedCodeSecurity]
public static extern int getseven();
[DllImport("MecDll.dll"), System.Security.SuppressUnmanagedCodeSecurity]
public static extern int getsevenmec();
Console.WriteLine("{0}" , getseven() );
Console.WriteLine("{0}" , getsevenmec() );
test.dll中的代码:
extern "C"
{
__declspec(dllexport) int __stdcall getseven() {
return 7;
}
}
添加到 MecDll.dll 的代码:
extern "C"
{
__declspec(dllexport) int __stdcall getsevenmec() {
return 8;
}
}
当我 运行 测试时,我从 test.dll 打印了 7,然后进程挂在黑色 window 上。
我在进程资源管理器中看到 dll 已加载。
测试 C# 代码是用任何 CPU 编译的,DLL 是用 x64 编译的。
有什么想法吗?
它是一个静态变量的构造函数,在构造函数中,套接字和定义的负数之间有一个==,在定义的负数之前添加(DWORD)解决了这个问题。
谢谢本
我正在将托管 C++ DLL (MecDll) 从 x86 移植到 x64。 C# 中的测试代码:
[DllImport("test.dll"), System.Security.SuppressUnmanagedCodeSecurity]
public static extern int getseven();
[DllImport("MecDll.dll"), System.Security.SuppressUnmanagedCodeSecurity]
public static extern int getsevenmec();
Console.WriteLine("{0}" , getseven() );
Console.WriteLine("{0}" , getsevenmec() );
test.dll中的代码:
extern "C"
{
__declspec(dllexport) int __stdcall getseven() {
return 7;
}
}
添加到 MecDll.dll 的代码:
extern "C"
{
__declspec(dllexport) int __stdcall getsevenmec() {
return 8;
}
}
当我 运行 测试时,我从 test.dll 打印了 7,然后进程挂在黑色 window 上。 我在进程资源管理器中看到 dll 已加载。
测试 C# 代码是用任何 CPU 编译的,DLL 是用 x64 编译的。
有什么想法吗?
它是一个静态变量的构造函数,在构造函数中,套接字和定义的负数之间有一个==,在定义的负数之前添加(DWORD)解决了这个问题。 谢谢本