Instantiating another CoClass from a CoClass method in the same component
-
Dear fellow CPians, I have a simple COM component with two coclasses. I'd like to be able to instantiate one CoClass from a method of the other CoClass and be able to access the instantiated CoClasse's methods directly, and not through its interface (so I can supply it with some object data, not only basic data types). Is there a way to do this? There should be, as the two CoClasses are under the same application and library. I only know the CoCreateInstance method, but with this method I only have access to the interface for the new created object. Thanks in advance for your time with this. Best regards. G. Raven
-
Dear fellow CPians, I have a simple COM component with two coclasses. I'd like to be able to instantiate one CoClass from a method of the other CoClass and be able to access the instantiated CoClasse's methods directly, and not through its interface (so I can supply it with some object data, not only basic data types). Is there a way to do this? There should be, as the two CoClasses are under the same application and library. I only know the CoCreateInstance method, but with this method I only have access to the interface for the new created object. Thanks in advance for your time with this. Best regards. G. Raven
Yes, U can use
CComObject
class for this. Suppose u have a collection classCTables
ofCTable
.CTables
has a method calledItem
which is supposd to rtn aCTable
object and we need to initialize a private member calledOrdinal
inCTable
. So theItem
method ofCTables
will be STDMETHODIMP CTables::Item(ITable **pT) { CComObject *objTable; objTable->CreateInstance(&objTable); objTable->Ordinal = 117; *pT= NULL; objTable->QueryInterface(IID_ITable, reinterpret_cast<void**>(pT) ); return S_OK; } does this make sence....mil10 -
Yes, U can use
CComObject
class for this. Suppose u have a collection classCTables
ofCTable
.CTables
has a method calledItem
which is supposd to rtn aCTable
object and we need to initialize a private member calledOrdinal
inCTable
. So theItem
method ofCTables
will be STDMETHODIMP CTables::Item(ITable **pT) { CComObject *objTable; objTable->CreateInstance(&objTable); objTable->Ordinal = 117; *pT= NULL; objTable->QueryInterface(IID_ITable, reinterpret_cast<void**>(pT) ); return S_OK; } does this make sence....mil10