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

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

问题描述

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

解决方案

不,您不能直接这样做。 64位进程只能执行64位代码,32位进程只能执行32位代码。



技巧是使用多个进程....(注意,这可以为非可视化代码,甚至对于GUI元素,尽管可能会有一些小但有问题的视觉元素的行为。)



最常见的解决方案是将32位dll包装在一个不在进程的COM服务器中,您可以通过64/32位屏障调用。 (这两种方式,您可以创建一个64位的进程COM服务器,也可以从32位应用程序调用它。)



是的,还有其他方法想到这个,但最常见的是使用COM:


  1. 创建一个新的32位的进程COM服务器,托管32位
    DLL并显示32位dll所需的功能。

  2. 从您的64位代码调用此COM服务器

我应该补充说,它也是可以创建新的32位COM服务器作为进程内的COM服务器,然后配置COM +来运行它。 COM +将会运行它,并且奇怪地运行您的32位进程COM服务器的进程,您可以透明地从32位和64位代码中调用它,就好像它正在进行中一样。 (注意,如果COM服务器是一个GUI控件,出于进程可能会或可能不起作用,我所使用的团队已经成功完成了,但是有一些复杂性 - 其中一些不能被克服 - 与挂钩父级有关窗口和控件在整个过程边界无法完成。)


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?

解决方案

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.

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.)

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.)

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

  1. Create a new 32 bit out of process COM server that hosts your 32 bit DLL and exposes the needed functionality from the 32 bit dll.
  2. Call this COM server from your 64 bit code

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天全站免登陆