Once in a while, a COM service that I've implemented will get into a state where my C++ client application will start failing to create the COM object due to an E_NOINTERFACE
error. The client application is a one-time run (non-persistent) .exe that I run frequently.
To begin with, the COM service will be working fine most of the time, but all of a sudden CoCreateInstance()
would start returning E_NOINTERFACE
. To add to the confusion, a VBScript that I wrote continues to run succesfully and creates the COM object without any problem.
If I restart the COM service, all will be back to normal and my C++ application will start working again.
Below are the C++ and VBScript snippets that I run.
C++
ISampleCom *MyComObj;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
// Create COM object
hr = CoCreateInstance(CLSID_SampleCom, 0, CLSCTX_LOCAL_SERVER, IID_ISampleCom, (void**)&MyComObj);
if(FAILED(hr))
printf("\r\nFailed to create COM object.");
VBScript
dim version
set mycomobj = CreateObject("MyCom.Sample")
mycomobj.GetVersion(version)