views:

92

answers:

3

My computer runs Windows 7 X64 Enterprise Edition. I need x86 mode for my executable as I use Visual Foxpro OLEDB driver. I thought it was required to compile library DLLs which are used by this exe as "X86". However, DLLs compiled with "Any CPU"seem to work which is quite convenient as they are used somewhere else and no need to maintain 2 copies. Just wondering how it works and should I continue like this ?

+2  A: 

This is fine. As long as the executable is compiled targetting x86, any "Any CPU" targeted assembly will get loaded as x86.

You just can't load an assembly explicitly targeting x64, as that won't work in a 32bit application.

Reed Copsey
+2  A: 

Any CPU DLLs will JIT compile to either x86 or x64 if the process is x64 or x86. As long as your exe is compiled as x86, the DLL will be JITed as x86. If your exe was x64 the DLL would be JITed as x64.

+1  A: 

The decision is made when your .exe is loaded. The 32BIT flag in the assembly metadata header will determine whether the 32-bit or the 64-bit of the CLR is loaded. And, most significantly, the x86 or the x64 JIT compiler. After that, the JIT compiler generates the proper flavor of machine code, regardless of the bitness of any of the DLLs that are loaded afterward.

Thus, only the target platform setting for the EXE matters.

Hans Passant