【发布时间】:2016-08-12 19:57:39
【问题描述】:
我有一个接口的 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);
【问题讨论】:
-
感谢您的建议。在 Visual Studio 中创建一个简单的 ATL COM 类会产生一些远非最小示例的东西。也许问题还不够清楚,但我尝试找到方法来做我需要的事情,而不是修复代码。
-
你肯定需要展示一些相关的代码。
-
我添加了一些代码,希望更清楚。