简体   繁体   中英

Will dll be loaded as 32bit or 64bit when exe is x86(32bit) on a 64bit machine?

In VS2008, for example, I have an exe built as x86(32bit) because I want it runs in 32bit even on 64bit machine. This exe will dynamically load other dlls through reflection and invoke.

Now my question is, if I build my dll as "All CPU", instead of x86, and when I run the exe host on a 64 bit machine, once my dll gets loaded, or called, the dll will be treated as 64bit or 32bit? (My test shows it is treated as 32bit, but I want to confirm with you all. I think in general, 32bit cannot access 64bit. Since the exe is 32bit, so the dlls will be always loaded as 32bit?)

Thanks

Yes, you are correct. Unless you jump through some serious hoops, every part of the process (at least the user code parts) will be 32-bit.

If the DLL to be loaded it also marked as AnyCPU then there won't be any problems.

If you have an AnyCPU EXE (for example) which is running on a 64-bit computer (so it's an x64 process) which then attempts to load an x86 DLL (which is not marked as AnyCPU) then it will fail with a runtime exception ( BadImageFormatException )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM