Cocreateinstance Returning E_Nointerface Even Though Interface Is Found

CoCreateInstance returning E_NOINTERFACE even though interface is found

If your COM server is running in a different process, or a different apartment in the same process, COM needs to know how to package and transmit parameters when you make calls to your interface. This process is called "marshaling".

If you define a custom interface, you need to implement marshaling for it using one of the following approaches.

  • Standard marshaling: have the MIDL compiler to generate a proxy
    and stub which you must register on the system. This is probably the best option since you have already defined your interface.
  • OLE Automation marshaling: you define an automation compatible
    custom interface and use the
    marshaller which is already part of
    the COM framework
  • Custom marshaling: you implement the methods of IMarshal

When you are debugging your COM server, although you see that you are returning your custom interface in the call to QueryInterface, it does not make it across the process boundary because COM cannot figure out how to marshal that interface, hence the client sees E_NOINTERFACE.

UPDATE (based on your comment)

If this is an existing COM server app then you probably already have a proxy/stub. You need to register this on both the client and server. Could it be that you were testing this on a new machine(s) and you simply forgot to register this? To register you simply do regsvr32 on the proxy/stub dll.

CoCreateInstance Returning E_INVALIDARG

You need to take the address of p_Interface and pass that to CoCreateInstance. As it is you're just passing a NULL pointer for the last argument.

DllGetClassObject return No such interface supported while CoCreateInstance can find it successful

CoCreateInstance (for in-proc servers) works in two stages. First, it loads the DLL and calls DllGetClassObject with the CLSID you pass, asking for IClassFactory interface. Second, it calls IClassFactory::CreateInstance on the pointer thus obtained, with the IID you pass.

The object that DllGetClassObject knows how to create - the class factory - does not normally itself implement any interfaces other than IClassFactory and, of course, IUnknown.



Related Topics



Leave a reply



Submit