Question... loading unmanaged dll in x64 system
-
is this possible to load unmanaged dll? When changing "target platform" to x86. It does work ok. But we prefer to keep it AnyCPU state. We keep getting "BadImageException" error on this when using ANYCPU state.
As far as I know, you can't mix 32-bit and 64-bit in the same process. A 32-bit EXE can't load a 64-bit DLL, and vice-versa. So if your unmanaged DLL is only available as 32-bit, you need to build your process as 32-bit (x86)... The "AnyCPU" setting is probably defaulting to 64-bit, because it doesn't detect any managed 32-bit assemblies in the project.
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels) -
is this possible to load unmanaged dll? When changing "target platform" to x86. It does work ok. But we prefer to keep it AnyCPU state. We keep getting "BadImageException" error on this when using ANYCPU state.
As Ian said, Windows only deals with homogeneous processes, so all the code must be 32-bit or all of it 64-bit. A managed app targetting "AnyCPU" gets launched as 64-bit on a 64-bit OS, and will refuse to load 32-bit code. If you have unmanaged dependencies, the practical way is NOT to use "AnyCPU" and therefore it is a pitty that (1) it is the default, and (2) Visual Studio Express doesn't really give you direct access to any other setting. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum