简体   繁体   中英

Why does my x64 bit app able to load a x86 bit DLL?

I use Teststand 64 bit (National Instrument) with one of my DLL as follow :

  • Teststand (64 bits) calls A.dll
  • A.dll is targeting "Any CPU" and references B.dll
  • B.dll is also targeting "Any CPU" and references C.dll
  • C.dll targets "x86" and is in charge of database access (ADO.NET)

If I reference C.dll directly from Teststand 64 bits, I get the failure that it is unable to load the DLL as it recognize it to be 32 bits. This was done by purpose and the result failed just as expected.

The problem here is that I don't understand why it works when Teststand calls A.dll. C.dll succeeds in doing its job and I would have swear that this should have given an exception or any kind of error but no.

In my head and from what I've read about x86 and x64 together is that x64 can't call on x86 target software.

Does someone has any kind of explanation for this?

I would like to understand what is going on to better code my libraries because this is becoming for me a DLL hell!

In the old days, dll have always been compield for a specific binarity. We still ahve those around. I like to call the "native dll's".

.NET DLL and programms break with that. They are "bitness agnostic". The same compiled MSIL can be run as x64 and x32, depending on the framework executing it on the computer. It could even run as x128 or x16, if we ever would get frameworks and OS for that.

As long as you keep it to .NET DLL's, binarity is not an issue. It can sometimes enter with Memory constraints, but overall we ignore it. Once you start mixing in native DLL's, binarity suddenly becomes everything.

I can only tell that A.DLL and B.DLL seem to be .NET DLL's. I can not tell wich variant "Teststand.exe" and C.dll are. Or the ADO.Net DLLS being called by C.DLL. My best guess is that the the unbroken line of .NET Code is long enough, binarity does not mater. Testrand onyl cares what A.dll returns, not caring how it got that result. And B.dll can call C.dll the .NET way, where binarity does not mater (you never hand around naked pointers).

But if you try to call the x32 only C.DLL from Testrand directly, it seems to break.

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