32bit dll in 64bit application in c#
Asked Answered
A

3

6

Hello
I want to create a 64bit application in c# and I wan't to use in it a dll created in C++ builder (32bit). But when I try to load the dll the application crashes. When built in 32bit it works. Is there a way to use this dll in a 64bit app?

Aschim answered 29/3, 2011 at 21:4 Comment(0)
S
8

No this is not possible. A process in Windows is either 32 or 64 bit and it can only load DLL's which match. Any attempt to load a DLL which does not match will fail and produce an error.

If you need to match 32 and 64 bit code you need to use multiple processes. In this case though I would just make the application 32 bit or the DLL 64 bit

Starcrossed answered 29/3, 2011 at 21:13 Comment(0)
D
1

Do you want to build a 64-bit application, or you want to build an application that will run in a 64-bit environment? Your application can run perfectly fine in a 64-bit environment even when the target platform is x86.

Demimondaine answered 29/3, 2011 at 21:15 Comment(1)
I need a 64bit application to use GetModuleBaseName WINAPI function to get 64bit application's exe name. When it is used in 32bit application running on 64bit OS it can retrieve only 32bit processes' names.Aschim
R
0

You cannot load a 32-bit DLL into a 64-bit process on Windows.

I have never tried it myself, but you might be able to create a seperate 32-bit application that can run in a different process and act as a proxy for the DLL. Your application could then run 64-bit and communicate with the DLL with remote procedure calls over WCF.

If performance is a concern, then your best bet would be to rebuild the DLL in 64-bit, if possible.

Rigatoni answered 29/3, 2011 at 21:8 Comment(1)
WCF - I think it is too difficult for me (at least for now). I would rather use file mapping for sharing data between these two apps. However I'm considering rewriting the dll into 64bit, but as c++ builder is only 32bit, I would need to use VS, which I am not familiar with.Aschim

© 2022 - 2024 — McMap. All rights reserved.