简体   繁体   English

c#中64位应用程序中的32位dll

[英]32bit dll in 64bit application in c#

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). 我想在c#中创建一个64位应用程序,我不想在其中使用在C ++ builder(32bit)中创建的dll。 But when I try to load the dll the application crashes. 但是当我尝试加载dll时,应用程序崩溃了。 When built in 32bit it works. 当它在32位内置时,它可以工作。 Is there a way to use this dll in a 64bit app? 有没有办法在64位应用程序中使用此DLL?

No this is not possible. 不,这是不可能的。 A process in Windows is either 32 or 64 bit and it can only load DLL's which match. Windows中的进程是32位或64位,它只能加载匹配的DLL。 Any attempt to load a DLL which does not match will fail and produce an error. 任何加载不匹配的DLL的尝试都将失败并产生错误。

If you need to match 32 and 64 bit code you need to use multiple processes. 如果需要匹配32位和64位代码,则需要使用多个进程。 In this case though I would just make the application 32 bit or the DLL 64 bit 在这种情况下,虽然我只是使应用程序32位或DLL 64位

Do you want to build a 64-bit application, or you want to build an application that will run in a 64-bit environment? 您是要构建64位应用程序,还是要构建将在64位环境中运行的应用程序? Your application can run perfectly fine in a 64-bit environment even when the target platform is x86. 即使目标平台是x86,您的应用程序也可以在64位环境中完美运行。

You cannot load a 32-bit DLL into a 64-bit process on Windows. 您无法在Windows上将32位DLL加载到64位进程中。

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. 我自己从未尝试过,但您可能能够创建一个单独的32位应用程序,该应用程序可以在不同的进程中运行并充当DLL的代理。 Your application could then run 64-bit and communicate with the DLL with remote procedure calls over WCF. 然后,您的应用程序可以运行64位,并通过WCF进行远程过程调用与DLL通信。

If performance is a concern, then your best bet would be to rebuild the DLL in 64-bit, if possible. 如果性能是一个问题,那么最好的办法是尽可能以64位重建DLL。

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

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