是否可以创建和使用COM类而不在注册表中注册它? [英] Can I create and use a COM class without registering it in the registry?

查看:54
本文介绍了是否可以创建和使用COM类而不在注册表中注册它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个自定义的COM对象,最终将看起来与此类似:

I need to make a custom COM object that is going to end up looking similar to this:

static const GUID IID_ClientCommunicator = { 0x5219b44a, 0x874, 0x449e,{ 0x86, 0x11, 0xb7, 0x8, 0xd, 0xbf, 0xa6, 0xab } };
static const GUID CLSID_ClientCommunicator = { 0x5219b44b, 0x874, 0x449e,{ 0x86, 0x11, 0xb7, 0x8, 0xd, 0xbf, 0xa6, 0xab } };

class ATL_NO_VTABLE CClientCommunicator:
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CClientCommunicator, &CLSID_ClientCommunicator>,
    public IDispatchImpl<CClientCommunicator, &IID_ClientCommunicator, 0, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
    //Custom functions

};

此对象最终将作为属性传递给Internet Explorer中的窗口javascript对象,因此我可以从JavaScript调用我在此类中定义的函数。

This object is going to end up being passed as a property to the window javascript object in internet explorer so that I can call the functions I define in this class from JavaScript.

我的问题是,如果这一切都在单个可执行文件中完成,是否需要在注册表中注册COM对象?如果是,我的COM对象位于可执行文件中怎么办?

My question is, if this is all done in a single executable, do I need to register the COM object in the Registry? If yes, how do I do that if my COM object is in an executable?

推荐答案

@RaymondChen用户指出注释中有一个函数 CoRegisterClassObject 此处,可用于注册COM类,而无需将其添加到注册表中。

As user @RaymondChen pointed out in the comments there is a function CoRegisterClassObject here, which can be used to register COM classes without needed to add them to the registry.

此当然,只允许您在注册该可执行文件的范围内使用该COM类。

This of course only allows you to use that COM class in the scope of the executable which registered it.

这篇关于是否可以创建和使用COM类而不在注册表中注册它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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