如何从 64 位代码调用 32 位 DLL? [英] How can I call a 32-bit DLL from 64-bit code?

查看:51
本文介绍了如何从 64 位代码调用 32 位 DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 32 位 DLL 与 64 位 DLL 不匹配.如何从用 Delphi XE2 编写的 64 位应用程序调用这些 DLL?

I have some 32-bit DLLs that don't have matched 64-bit DLLs. How can I invoke these DLLs from a 64-bit application written in Delphi XE2?

推荐答案

不,您不能直接执行此操作.64位进程只能执行64位代码,32位进程只能执行32位代码.

No, you cannot directly do this. A 64 bit process can only execute 64 bit code, and a 32 bit process can only execute 32 bit code.

诀窍是使用多个进程......(注意这可以用于非可视化代码,甚至是 GUI 元素,尽管可视化元素可能存在一些小而有问题的行为.)

The trick is to use multiple processes.... (Note this can be done for non visual code, and even for GUI elements, though there can be some small but problematic behaviors for visual elements.)

最常见的解决方案是将 32 位 dll 包装在进程外 COM 服务器中,您可以跨 64/32 位屏障调用该服务器.(这是双向的,您可以创建 64 位进程外 COM 服务器,也可以从 32 位应用程序调用它.)

The most common solution is to wrap the 32 bit dll in an out of process COM server, which you can call across the 64/32 bit barrier. (This goes both ways, you can create a 64 bit out of process COM server and call it from a 32 bit application also.)

是的,还有其他方法可以构思,但最常见的是使用 COM:

Yes, there are other ways to conceive of this, but the most common is to use COM:

  1. 创建一个新的 32 位进程外 COM 服务器来承载您的 32 位DLL 并从 32 位 dll 公开所需的功能.
  2. 从您的 64 位代码调用此 COM 服务器

我应该补充一点,也可以将新的 32 位 COM 服务器创建为进程内 COM 服务器,然后配置 COM+ 来运行它.COM+ 将在进程外运行它,并神奇地在进程外运行您的 32 位进程内 COM 服务器,您可以在其中透明地从 32 位和 64 位代码调用它,就像它在进程中一样.(请注意,如果 COM 服务器是 GUI 控件,则退出进程可能会也可能不会起作用.与我合作的团队已经成功完成了这项工作,但是存在一些复杂性——其中一些无法克服——与挂钩父级相关无法跨进程边界完成的窗口和控件.)

I should add that it is also possible to create the new 32 bit COM server as an in-process COM server, and then configure COM+ to run it. COM+ will run it out of process, and magically run your 32 bit in process COM server out of process, where you can call it from 32 and 64 bit code transparently, as if it was in process. (Note, if the COM server is a GUI control, going out of process may or may not work. The team I work with has done it successfully, but there are complexities -- some of which cannot be surmounted -- related to hooking parent windows and controls that cannot be done across the process boundary.)

这篇关于如何从 64 位代码调用 32 位 DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆