Anton Vainer Anton Vainer - 1 year ago 112
C# Question

Calling x64 C++ DLL from C#, process hangs (update)

I'm porting a managed C++ DLL (MecDll) from x86 to x64.
test code in 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() );

code in test.dll:

extern "C"
__declspec(dllexport) int __stdcall getseven() {
return 7;

Code added to MecDll.dll:

extern "C"
__declspec(dllexport) int __stdcall getsevenmec() {
return 8;

When I run the test, I get the 7 printed from the test.dll and then process just hangs on a black window.
I see in process explorer that the dll is loaded.

The test C# code is compiled with any CPU and the DLL's with x64.

Any ideas?

Answer Source

it was a constructor of a static variable, inside the constructor there was a == between a socket and a defined negative number, adding (DWORD) before the negative number to the define fixed the issue. thanks Ben

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download