简体   繁体   English

当exe在64位计算机上为x86(32bit)时,dll是否将以32位或64位加载?

[英]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. 例如,在VS2008中,我有一个以x86(32bit)形式构建的exe,因为我希望它甚至可以在64位计算机上以32位运行。 This exe will dynamically load other dlls through reflection and invoke. 该exe文件将通过反射和调用动态加载其他dll。

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? 现在我的问题是,如果我将dll设为“所有CPU”而不是x86,并且在64位计算机上运行exe主机时,一旦加载或调用了我的dll,该dll将被视为64位或32位? (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?) (我的测试显示它被视为32位,但是我想与大家确认。我认为通常32位无法访问64位。由于exe是32位,因此dll总是会加载为32位吗?)

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. 除非您遇到一些麻烦,否则过程的每个部分(至少用户代码部分)都是32位的。

If the DLL to be loaded it also marked as AnyCPU then there won't be any problems. 如果要加载的DLL也标记为AnyCPU那么不会有任何问题。

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 ) 如果您有运行在64位计算机(因此是x64进程)上的AnyCPU EXE(例如),然后尝试加载x86 DLL(未标记为AnyCPU),则它将由于运行时异常而失败( BadImageFormatException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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