直接访问C++ ATL COM对象

问题描述 投票:0回答:1

我有一个接口的 ATL/COM 实现,我需要在主代码中实例化它并传递给另一个 COM 对象。这个实现是用 C++ 实现的。

从我的主要 C++ 代码中,我想直接访问对象(不通过 COM 端口),并直接访问类成员和方法。

我认为正确的方法是在 ATL/COM 类中添加

DECLARE_NO_REGISTRY()
;然后调用
myCOMClass:CreateObject()
而不是
CoCreateInstance
;但我不知道如何使用这个(也没有找到任何例子)。

我尝试了几种组合,但没有成功。

在我的主要代码中:

//I added this line to call the lib directly
#include "comClass\StdAfx.h"
#include "comClass\comClass_i.c"
#include "comClass\comClass.h"

//I removed this line to bypass COM
//#import  "comClass\comClass.dll"

//What can I put here to replace this block, bypass COM
//and being able to access class members??
CoInitialize(NULL);
comClassInterface *myObject = NULL;
HRESULT hr = ::CoCreateInstance(__uuidof(comClass),
    NULL,
    CLSCTX_INPROC_SERVER,
    __uuidof(comClassInterface),
    (void**)&myObject);
c++ dll com atl
1个回答
1
投票

直接创建 COM 对象或多或少是“标准”的:

CComObject<comClass> *myObject;
CComObject<comClass>::CreateInstance(&myObject);

基本上就是这样..如果类不是抽象的,你也可以只执行“new comClass”,这通常是使用 ATL 时的情况。

© www.soinside.com 2019 - 2024. All rights reserved.