Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LoadLibrary fails under Vista x64

Right after I moved from XP to Vista,I realized my C# programs don't work.

This is the situation: I wrote a C++ dll that I use in my C# application.The DLL worked fine in XP,but when I moved to Vista it's not longer working in C#.

I tested it in Delphi,works fine,but C# - no.

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

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

It doesn't need C++ runtime,because Its compiled with the libraries and it works in Delphi on Vista,but not C#.

Where could the problem be?

Thanks in advance.

like image 554
Ivan Prodanov Avatar asked Dec 09 '22 20:12

Ivan Prodanov


1 Answers

On x64 platform the JIT will compile your program into x64, since your native C++ is compiled to x86 it will fail to load it.
You need to explicitly tell the JIT to compile your program to x86, you can do it using CorFlags or the project settings set the CPU type to x86 (Under Build/Platform target)

like image 180
Shay Erlichmen Avatar answered Dec 27 '22 19:12

Shay Erlichmen