使用 .Net Interop(使用 TlbImp 生成)时,我的 COM 对象拒绝在代理(dllhost)中执行
这很奇怪。
我们有一些托管 C++(程序集),它使用 TlbImp 生成的 .NET COM 互操作 dll 来调用 COM 对象。当我们注册 COM DLL 时,我们指定希望它在代理项(“DLLSurrogate”注册表项)中执行。
我们的 COM DLL 是 64 位的,并且在 64 位平台上执行。
当我们将程序集与 32 位应用程序(包含托管和非托管代码)集成时,对 COM 库的调用在 DllHost 内执行。同一应用程序的 64 位版本会导致调用在调用进程内执行。
纯非托管客户端应用程序(32 位和 64 位)在 64 位系统上正确执行,这表明(我希望)我们已经正确配置/安装了 COM 库。
此行为可能表明 .NET COM Interop 正在忽略注册表中的配置信息。 32 位客户端无法将 64 位 COM DLL 加载到其地址空间并默认使用代理项?不管怎样,这种行为对我们来说是灾难性的,因为 COM 库包含一个代表对某些硬件的访问的单例,并且可能有许多客户端进程。
以前有人注意到这种行为吗?
谢谢,
迈克 D
This is very odd.
We have some managed C++ (an assembly) which uses a .NET COM interop dll generated by TlbImp to make calls into a COM object. When we register the COM DLL we specify that we want it to execute within a surrogate (the "DLLSurrogate" registry entry).
Our COM DLL is 64-bit and is executing on a 64-bit platform.
When we integrate the assembly with a 32-bit application (which contains managed and unmanaged code) calls into the COM library execute within DllHost. A 64-bit build of the same application causes the calls to be executed within the calling process.
Pure unmanaged client applications (both 32 and 64 bit) execute properly on the 64-bit system which shows (I hope) that we have configured / installed the COM library properly.
This behaviour could indicate that the .NET COM Interop is ignoring the configuration information in the registry. The 32-bit client cannot load the 64-bit COM DLL into its address space and defaults to using a surrogate? Anyway, this behaviour is disastrous for us as the COM library contains a singleton representing access to some hardware and there maybe many client processes.
Has any one noted this behaviour before?
Thanks,
Mike D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个奇怪的要求,几乎总是相反;尝试从 64 位代码使用 32 位 COM 服务器。如果您有 32 位构建的服务器,那么请务必在进程内使用它,这比进程外代理更高效且更容易使用。
64 位版本的 Windows 上的注册表针对 32 位应用程序进行了虚拟化。所有 32 位 COM 注册都存储在 HKLM\Software\Wow6432Node 中。使用 Regedit.exe 验证 COM 服务器注册是否确实存在。
您还可能遇到 COM 服务器的代理/存根 DLL 问题。因为您的服务器在另一个进程中运行,所以需要它们。确保以 32 位和 64 位版本构建这些 DLL,并使用正确版本的 Regsvr32.exe 注册它们
This is an odd request, it is almost always the other way around; trying to use a 32-bit COM server from 64-bit code. If you have a 32-bit build of the server, then be sure to use it in-process, much more efficient and easier to get going than an out-of-proc surrogate.
The registry on a 64-bit version of Windows is virtualized for 32-bit apps. All 32-bit COM registration is stored in the HKLM\Software\Wow6432Node. Use Regedit.exe to verify that the COM server registration is actually present there.
You may also have an issue with the proxy/stub DLLs for the COM server. They'll be needed because your server runs in another process. Be sure to build those DLLs both in 32-bit and 64-bit versions and register them with the proper version of Regsvr32.exe