Reputation: 568
I have an ATL/COM implementation of an interface, which I need to instantiate in my main code and pass to another COM object. This implementation is in C++.
From my main C++ code, I would like to access directly to the object (not through the COM port), and access class members and methods directly.
I think that the way to go is to add DECLARE_NO_REGISTRY()
in the ATL/COM class; then call myCOMClass:CreateObject()
instead of CoCreateInstance
; but I do not know how to use this (and did not find any example).
I tried several combinations with no success.
In my main code:
//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);
Upvotes: 0
Views: 647
Reputation: 12235
More or less "standard" wat to create COM objects directly:
CComObject<comClass> *myObject;
CComObject<comClass>::CreateInstance(&myObject);
That's it basically.. You could also just do "new comClass" if the class is not abstract, which is normally the case when you use ATL.
Upvotes: 1