简体   繁体   English

在32位应用程序中使用64位DLL

[英]Using a 64bit DLL in a 32bit Application

XCode's ARC refactoring forced my Cocoa Library DLL to be 64bit, and I don't know if I can still DllImport that DLL from an x86 C# application. XCode的ARC重构将我的Cocoa库DLL强制为64位,我不知道是否仍然可以从x86 C#应用程序中DllImport该DLL。 Is this possible, and are there any consequences of doing so? 这可能吗,这样做有什么后果吗?

You cannot mix 32 bit and 64 bit code in a single process. 您不能在单个过程中混合使用32位和64位代码。 So the only way to use mix bitness code is to have more than one process. 因此,使用混合位代码的唯一方法是拥有多个进程。 You'll need some form of IPC to make it work. 您需要某种形式的IPC才能使其工作。 You cannot do it with DllImport since that is in-process. 您无法使用DllImport进行此操作,因为它正在进行中。

The problem is not really C# - it is the hosting process in the OS. 问题不是真正的C#,而是OS中的托管过程。 Since one process can only load DLLs with the same "bitness", either the process is 64bit or you cannot directly load your DLL. 由于一个进程只能加载具有相同“位”的DLL,因此该进程为64位,或者您无法直接加载DLL。 No matter what language or framework you are using. 无论您使用哪种语言或框架。

One solution would be to target the C# project to use "any" cpu or specifically point it to X64. 一种解决方案是将C#项目定位为使用“任何” cpu或将其专门指向X64。

Another solution would be to create a hosting process that you can communicate with using IPC or similar models. 另一个解决方案是创建一个托管过程,您可以使用IPC或类似模型与之通信。

The solution when necessary is to call an EXE in pipeline or similar. 必要时的解决方案是在管道中调用EXE或类似方法。 This assumes of course a 64 bit windows. 这当然假定为64位窗口。 If not, punt. 如果没有,平底锅。

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

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