建立一个DLL为免注册COM互操作使用C#/管理code [英] Setting up a DLL for registration-free COM Interop with C# / Managed code

查看:794
本文介绍了建立一个DLL为免注册COM互操作使用C#/管理code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的COM和必须创建一个COM包装为一个C ++ DLL,做一些功能,在它管理code访问。我主要是跟着这教程code项目创建一个COM ATL DLL。我创建了一个生成后步骤调用tlbimp.exe是对COM DLL创建的包装。

I am new to COM and have to create a COM wrapper for a C++ dll, to make some functionality in it accessible for managed code. I mainly followed this tutorial on code project to create a COM ATL dll. I created a post-build-step that calls tlbimp.exe on the COM dll to create the wrapping.

添加引用,tlbimp.exe是创建工作的DLL,我也得到code完成了对我的COM DLL的方法,并可以编译使用该DLL管理code。然而,运行code会导致以下异常:

Adding a reference to the dll that tlbimp.exe creates works, and I get code completion for methods on my COM dll, and can compile managed code that uses that dll. However, running that code leads to the following exception:

Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the COM class factory 
for component with CLSID {FD6F73D2-0208-455A-953A-C911EC2CAEAB} failed due to the following error: 
80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
//...

如果我正确地理解这个例外和MSDN上的文档,下一步将是设立免注册COM互操作的免注册的一部分。我已经看过了各种指南,如这个和的这一个,但我还是不明白我要做。

If I understand this exception and the documentation on MSDN correctly, the next step would be to set up the 'registration-free' part of registration-free COM interop. I have looked at various guides such as this one and this one, but I still don't understand what I have to do.

所以我的问题是:

什么是我需要让我的新创建.NET兼容COM DLL加载未经登记的基本步骤是什么?

What are the basic steps I need to take to make my newly created .Net-compatible COM dll load without registration?

我必须写一个清单我的.Net应用程序,使用的COM DLL? 我必须写一个清单我的COM DLL?或者说tblimp.exe该DLL从它产生的?

Do I have to write a manifest for my .Net app that uses the COM dll? Do I have to write a manifest for my COM dll? Or the DLL that tblimp.exe generates from it?

推荐答案

我相信你不会看到隔离属性在Solution Explorer中,因为您手动生成的互操作组装tlmbimp.exe,然后将其添加到项目中。

I believe you don't see the Isolated property in Solution Explorer, because you manually generated the Interop assembly with tlmbimp.exe, then added it to the project.

不要那样做。删除现有的引用,然后添加一个新的,在那里你会浏览原始的非托管COM DLL。在参考文献管理器,点击 COM 在左侧,点击浏览按钮,然后浏览并选择非托管的COM DLL。 Visual Studio将做休息。

Don't do that. Remove that existing reference, then add a new one, where you'd browse for the original unmanaged COM DLL. In Reference Manager, Click COM at the left, click Browse button, then browse for and select your unmanaged COM DLL. Visual Studio will do the rest.

这篇关于建立一个DLL为免注册COM互操作使用C#/管理code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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