Visual C#-参考>添加参考...> COM:如何填充该列表?

Visual C# - References > Add Reference… > COM: How is that list populated?
2021-07-22
  •  译文(汉语)
  •  原文(英语)

我正在尝试在Visual C ++ 2010(Express)中开发COM组件,并且希望能够从Visual C#2010(Express)程序中使用它.

我的COM DLL尚未完成,但是我定义了DllRegisterServerDllUnregisterServer函数,它们将大量内容写入HKEY_CLASSES_ROOT和子项中.除其他外,我有以下按键:

HKEY_CLASSES_ROOT\My.Components.1\CLSID
    Default Value: {DB05EA30-0320-4D40-A530-6DEAD03D3850}

HKEY_CLASSES_ROOT\CLSID\{DB05EA30-0320-4D40-A530-6DEAD03D3850}
    Default Value: My Components
    Sub Key: InprocServer32
        Default Value: Absolute path of the .dll
        Threading Mode: Apartment
    Sub Key: ProgID
        Default Value: My.Components.1
    Sub Key: TypeLib
        Default Value: {DB05EA31-0321-4D41-A531-6DEAD03D3851}
    Sub Key: Version
        Default Value: 1.0

HKEY_CLASSES_ROOT\TypeLib\{DB05EA31-0321-4D41-A531-6DEAD03D3851}
    Sub Key: 1.0
        Sub Key: 0
            Sub Key: win32
                Default Value: Absolute path of the .tlb

Microsoft JScript能够尝试实例化COM对象,尽管由于工厂不完整,所以所做的只是输出DllGetClassObject的错误代码.

另一方面,Visual C#2010(或至少是Add Reference ...窗口)似乎没有注意到注册的COM对象的存在,该对象未显示在列表中.我很清楚这些对象只是已安装的COM对象的一个​​子集.

什么时候将出现一个COM对象?我想念什么?

编辑

我知道"浏览"选项卡,但给人的印象是,一流注册的COM对象应该在不显式搜索它们的情况下显示,但事实并非如此.

速聊1:
填充列表时,可以使用Process Monitor跟踪VS执行的注册表访问.
速聊2:
有趣的是,我将来可能会尝试.感谢您的评论.
解决过程1
Sub Key: 1.0

必须先分配此键的默认值,然后才能在COM选项卡中显示类型库.它必须包含对类型库的描述.样板短语是"Acme Foo Type Library 1.0",其中"Acme"是您的公司名称,"Foo"是服务器或产品名称.

否则我会优先使用"浏览"选项卡,而"COM"选项卡太慢.您会发现:)

速聊1:
主席先生,您是正确的.非常感谢你的帮助.我模仿了现有条目的结构,但是没有注意到版本密钥的默认值.您确实给我留下了深刻的印象.顺便说一下,不需要FLAGS.我仍然无法导入对象,但出现错误"无法注册ActiveX类型库",但我知道DLL仍然存在问题.如果我可以问,您对学习COM / OLE / ActiveX有什么建议?在哪里可以找到有关COM注册的所有这些详细信息?
速聊2:
这些不是我所知道的详细记录的那种细节.无论如何,大多数COM书籍都已绝版.辛勤学校和SO是很好的资源.我上那所学校.

I'm trying to develop a COM component in Visual C++ 2010 (Express) and I want to be able to consume it from a Visual C# 2010 (Express) program.

My COM DLL is not yet complete, however I defined the DllRegisterServer and DllUnregisterServer functions and they write a lot of stuff into HKEY_CLASSES_ROOT and subkeys. Among the others, I have the following keys:

HKEY_CLASSES_ROOT\My.Components.1\CLSID
    Default Value: {DB05EA30-0320-4D40-A530-6DEAD03D3850}

HKEY_CLASSES_ROOT\CLSID\{DB05EA30-0320-4D40-A530-6DEAD03D3850}
    Default Value: My Components
    Sub Key: InprocServer32
        Default Value: Absolute path of the .dll
        Threading Mode: Apartment
    Sub Key: ProgID
        Default Value: My.Components.1
    Sub Key: TypeLib
        Default Value: {DB05EA31-0321-4D41-A531-6DEAD03D3851}
    Sub Key: Version
        Default Value: 1.0

HKEY_CLASSES_ROOT\TypeLib\{DB05EA31-0321-4D41-A531-6DEAD03D3851}
    Sub Key: 1.0
        Sub Key: 0
            Sub Key: win32
                Default Value: Absolute path of the .tlb

Microsoft JScript is able to attempt the instantiation of the COM object, although since the factory is incomplete, all that is does is output the error code of DllGetClassObject.

On the other side, Visual C# 2010 (or at least the Add Reference... window) doesn't seem to notice the presence of the registered COM object, which doesn't show up in the list. It's pretty clear to me that those objects are only a subset of the installed COM objects.

At what point a COM object will show up there? What am I missing?

Edit

I'm aware of the Browse tab, but I was under the impression that first-class registered COM objects are supposed to show up without explicitly searching for them, but maybe that's not the case.

Talk1:
You could use Process Monitor to trace registry accesses performed by VS when populating the list.
Talk2:
Interesting, I may try this out in the future. Thank you for your comment.
Solutions1
Sub Key: 1.0

This key's Default value must be assigned before the type library can show up in the COM tab. It must contain a description of the type library. The boilerplate phrase is "Acme Foo Type Library 1.0" where "Acme" is your company name and "Foo" is the server or product name.

Using the Browse tab is otherwise my heavy preference, the COM tab is too slow. You'll find out :)

Talk1:
Sir, you are correct. Thank you so much for your help. I mimicked the structure of existing entries but I didn't notice the default value on the version key. I'm really impressed that you did. And by the way FLAGS is not required. I still cannot import my object, I get an error "Could not register the ActiveX type library" but I'm aware that there is still something wrong with the DLL. If I can ask, what do you recommend to learn COM/OLE/ActiveX? Where can I find all these details on COM registration?
Talk2:
These are not the kind of details that are ever documented in detail that I know of. Most COM books are out of print anyway. The School of Hard Knocks and SO are good resources. I attended that school.
转载于:https://stackoverflow.com/questions/17397362/visual-c-sharp-references-add-reference-com-how-is-that-list-populated

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入