0
votes

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);
1
Thanks for the suggestion. Creating a simple ATL COM class in Visual Studio produces something which is far from a minimal example. Maybe the question is not clear enough, but I try to find the method to do what I need rather than fixing a code. - seb007
You definitely need to show some relevant code. - Roman R.
I added some code, hoping it is more clear. - seb007

1 Answers

1
votes

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.