I need to integrate some legacy 32-bit code - for which I don't have the source code, into a project in such a way that it can be called from a 64-bit .NET assembly. The original code is implemented as a 32-bit COM object in a DLL. Windows doesn't allow direct calls from 64 to 32-bit objects, so I'm looking for inspiration on how to deal with this situation.
我需要将一些遗留的32位代码(我没有源代码)集成到一个项目中,以便可以从64位.NET程序集中调用它。原始代码在DLL中实现为32位COM对象。 Windows不允许从64位到32位对象的直接调用,所以我正在寻找如何处理这种情况的灵感。
How can a legacy 32-bit COM object be accessed from a 64-bit .NET assembly?
如何从64位.NET程序集访问传统的32位COM对象?
UPDATE: We discovered that the COM component was itself a wrapper around some ANSI C, which we founf the original source for. We were able to compile that in Visual Studio as a native 64-bit dll, and import that into .NET - sorry to move the goalposts!
更新:我们发现COM组件本身就是一些ANSI C的包装器,我们为它提供了原始源代码。我们能够在Visual Studio中将其编译为本机64位dll,并将其导入.NET - 抱歉移动球门柱!
3 个解决方案
#1
8
The best approach is to make an out of process COM server that wraps your 32-bit DLL. You can then call this from 64bit code.
最好的方法是创建一个包装32位DLL的进程外COM服务器。然后,您可以从64位代码调用它。
Here is an explanation of the basic concepts.
以下是对基本概念的解释。
#2
3
What you need to do is create two processes communicating with IPC. This way, one can be 32 bit, and one can be 64 bit. You need to create a 32 program which links with the COM object and exposes its API through some IPC mechanism such as a named pipe. This way your .NET program can access it from another process.
您需要做的是创建两个与IPC通信的进程。这样,一个可以是32位,一个可以是64位。您需要创建一个与COM对象链接的32程序,并通过某种IPC机制(如命名管道)公开其API。这样您的.NET程序就可以从另一个进程访问它。
#3
3
Check out this blog post. You can reference a 32 bit COM assembly from a 64 bit .NET application using a runtime callable wrapper. The short version is the following...
看看这篇博文。您可以使用运行时可调用包装器从64位.NET应用程序引用32位COM程序集。简短版本如下......
-
Use tlbimp.exe to create a 64 bit Runtime Callable Wrapper:
使用tlbimp.exe创建一个64位运行时可调用包装器:
tlbimp.exe foo.dll /machine:x64 /out:Interop.Foo.dll
tlbimp.exe foo.dll / machine:x64 /out:Interop.Foo.dll
-
Register the COM assembly (not the RCW) if you haven't already:
如果您还没有注册COM程序集(而不是RCW):
regsvr32.exe foo.dll
-
Reference the RCW (eg.
Interop.Foo.dll
) from your application. Change your Build Configuration to x64 and let 'er rock.从您的应用程序引用RCW(例如Interop.Foo.dll)。将构建配置更改为x64,让我们摇滚吧。
#1
8
The best approach is to make an out of process COM server that wraps your 32-bit DLL. You can then call this from 64bit code.
最好的方法是创建一个包装32位DLL的进程外COM服务器。然后,您可以从64位代码调用它。
Here is an explanation of the basic concepts.
以下是对基本概念的解释。
#2
3
What you need to do is create two processes communicating with IPC. This way, one can be 32 bit, and one can be 64 bit. You need to create a 32 program which links with the COM object and exposes its API through some IPC mechanism such as a named pipe. This way your .NET program can access it from another process.
您需要做的是创建两个与IPC通信的进程。这样,一个可以是32位,一个可以是64位。您需要创建一个与COM对象链接的32程序,并通过某种IPC机制(如命名管道)公开其API。这样您的.NET程序就可以从另一个进程访问它。
#3
3
Check out this blog post. You can reference a 32 bit COM assembly from a 64 bit .NET application using a runtime callable wrapper. The short version is the following...
看看这篇博文。您可以使用运行时可调用包装器从64位.NET应用程序引用32位COM程序集。简短版本如下......
-
Use tlbimp.exe to create a 64 bit Runtime Callable Wrapper:
使用tlbimp.exe创建一个64位运行时可调用包装器:
tlbimp.exe foo.dll /machine:x64 /out:Interop.Foo.dll
tlbimp.exe foo.dll / machine:x64 /out:Interop.Foo.dll
-
Register the COM assembly (not the RCW) if you haven't already:
如果您还没有注册COM程序集(而不是RCW):
regsvr32.exe foo.dll
-
Reference the RCW (eg.
Interop.Foo.dll
) from your application. Change your Build Configuration to x64 and let 'er rock.从您的应用程序引用RCW(例如Interop.Foo.dll)。将构建配置更改为x64,让我们摇滚吧。