Reputation: 91
I am a COM beginner. I have a DLL file that I register using the regsvr32
command. In the COM client, I try to use the CoCreateInstance
function, but it doesn't work. This is my code:
IMessageBox *pBox;
hr = CoCreateInstance(
__uuidof(IMessageBox),
NULL,
CLSCTX_INPROC_SERVER,
IID_IUnknown,
(void **)&pBox
);
IMessageBox
is the interface which is defined in my DLL file. It implements the IDispatch
interface. The result of hr
displays the error REGDB_E_CLASSNOTREG
. How do I use the CoCreateInstance
function?
Upvotes: 2
Views: 1752
Reputation: 612934
Well, the error tells you what is the problem. The class you are requesting is not registered in the COM registry. It could be that the IID of class that you registered is not the one that you are requesting. Another common failure mode is that you registered a 32 bit DLL and your calling process is 64 bit. Or vice versa.
Upvotes: 2
Reputation: 94319
Instead of __uuidof(IMessageBox)
you have to pass the UUID of the class you want to instantiate - i.e. the class you registered previously using regsrv32
.
Upvotes: 4