CoCreateInstance C++ help

krwell

Senior member
Feb 11, 2001
454
0
0
Hey Guys I'm trying to fix a program for work and I've found where the problem is, but I do not have enough Visual C++ background to solve it. So see if you guys can.

Declaration:

CTimerEvents m_TimerEngine;



Creation:

HRESULT hr = m_TimerEngine.CoCreateInstance(__uuidof(TimerEngine));
if (SUCCEEDED(hr)) {
do something...
} else {
do something...
}



hr always has the value of 0x8004154 = -2147221164 which means about the class not being registered. Whoever can solve this for me I owe them. Thanks
 

alisajid

Member
Jun 29, 2001
194
0
0
CoCreateInstance is a COM API function that allows you to create an instance of a COM object and to obtain an IUnknown interface pointer for that object. I forgot the exact prototype, but its something like CoCreateInstance( CLSID, void** punk, (other stuff));

I'm not exactly sure what you're doing... Please provide more information.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
CoCreateInstance instance method of CTimerEvents most likely encapsulates the call to the CoCreateInstance COM API method, so it wouldn't have the same signature. In this line...

(__uuidof(TimerEngine));

Is 'TimerEngine' valid? If it's saying class not registered, you most likely simply need to register the typelib associated with that type. Find the binary (.dll, or .tlb) and simply regsvr32 it. Run your code again, and it should work (again, assuming TimerEngine is valid).