在 64 位 .Net 应用程序中导入 32 位 dll [英] 32 bit dll importing in 64 bit .Net application

查看:32
本文介绍了在 64 位 .Net 应用程序中导入 32 位 dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我从昨天开始就一直在努力解决它,但没有成功.我有一个 32 位 Delphi DLL,我想将它导入到 .NET WIN 应用程序中.此应用程序必须建立在 ANY CPU 模式下.当然,抛出异常 BadImageFormatException,这意味着 64 位应用程序无法加载 x86 DLL.我用谷歌搜索并找到了一个解决方案,它说我必须做包装,但我不清楚.谁能告诉我如何解决这个问题,有什么可能的方法可以将 32 位 Delphi DLL 导入在任何 CPU 架构(64 位、32 位)或其他解决方案下构建的程序中?

I'm having a problem, I've been trying to solve it since yesterday but no luck. I have a 32-bit Delphi DLL which I want to import it in to a .NET WIN Application. This application has to be built on ANY CPU mode. Of course, the exception BadImageFormatException is thrown, which means that 64-bit applications can't load x86 DLLs. I googled around and found a solution, it said that I have to do wrapper, but it wasn't clear for me. Can anyone tell me how to solve this problem, is there any possible way that I can import a 32-bit Delphi DLL in to a program built under any CPU architecture (64-bit, 32-bit) or maybe another solution?

推荐答案

一般的想法是用托管的 32 位包装 dll 包装您的(非托管的)32 位 DLL 并使其 COM 可见.这允许通过其 COM 接口调用您的包装器 DLL.

A general idea could be to wrap your (unmanaged) 32-bit DLL with a managed 32-bit wrapper dll and make it COM visible. This allows calls to your wrapper DLL via its COM interface.

您可以使用 COM 代理使您的 COM dll 显示为进程外 COM 服务器.查看这个 SO 问题以获取有关此主题的更多信息:从 x64 访问 x86 COM.NET.

You can than use a COM surrogate to make your COM dll appear as an out of process COM server. Take a look at this SO question for some further information on this topic: Access x86 COM from x64 .NET.

这篇关于在 64 位 .Net 应用程序中导入 32 位 dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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