LoadLibrary error under Vista x64

Immediately after switching from XP to Vista, I realized that my C # programs did not work.

In this situation, I wrote a C ++ dll, which I use in my C # application. The DLL worked fine in XP, but when I switched to Vista, it no longer worked in C #.

I tested it in Delphi, it works fine, but C # doesn't.

I wrote additional code to make my check easier in C #.

if (LoadLibrary("blowfish.dll") == 0) { Misc.LogToFile("error", true); Application.Exit(); } 

C ++ runtime is not required because it is compiled with libraries and works in Delphi on Vista, but not in C #.

Where can the problem arise?

Thanks in advance.

+4
source share
3 answers

On the x64 platform, JIT will compile your x64 program, since your own C ++ is compiled on x86, it will not be able to download it.
You need to explicitly specify JIT to compile your x86 program, you can do it with CorFlags or the project settings set the CPU type to x86 (Within the Build / Platform object)

+11
source

Shay has a quick fix - make your entire application 32-bit so that it works under WOW64.

However, the β€œbest” solution is to rebuild your C ++ dll as 64-bit code so that your entire program can run natively on a 64-bit OS.

+2
source

If you usually compile, the CLR will launch your application as 64-bit on x64 Windows and 32-bit on x86 Windows. You must upload the correct custom image for the platform. One solution is to do as Shay suggested, and make your application run in the 32-bit CLR.

You can also make your application look at the size of the built-in pointer and load the correct own image.

 string blowfishdll = "blowfish.dll"; // detect 64-bit installations by looking at the native pointer size if( 64 == IntPtr.Size * 8 ) blowfishdll = "blowfish-x64.dll" if (LoadLibrary( blowfishdll ) == 0) { Misc.LogToFile("error", true); Application.Exit(); } 
+1
source

All Articles