0

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)
ykay
  • 1,877
  • 19
  • 24
  • 1
    Attach a debugger to the server when it starts failing. – Hans Passant Oct 03 '13 at 20:21
  • Would anything even reach the service if the client is getting E_NOINTERFACE at CoCreateInstance()? It seems like COM is not even recognizing it as an interface that exists on the system. – ykay Oct 03 '13 at 20:33
  • 1
    What happens if you change the code so that it passes id of `IUnknown` into `CoCreateInstance()` and then uses `QueryInterface()` to retrieve the interface of interest? – sharptooth Oct 04 '13 at 06:41
  • @ykay, perhaps that object creates tearoff interface pointers for `ISampleCom`, but somehow they're not being released. The VBScript may work all the time because that same object doesn't create tearoff interface pointers for `IDispatch`. – acelent Oct 08 '13 at 14:37

0 Answers0