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
Can This MACro Be Converted to a Function
In C++, Is There a Difference Between "Throw" and "Throw Ex"
Static Initialization and Destruction of a Static Library's Globals Not Happening with G++
Passing a Non-Copyable Closure Object to Std::Function Parameter
How to Call a C++ Method from C
Partial Template Specialization Based on "Signed-Ness" of Integer Type
Documenting Preprocessor Defines in Doxygen
Why Was the Restriction on the Comma Operator Being in a Constant Expression Removed in C++11
Programmatically Getting Per-Process Disk Io Statistics on Windows
How to Turn on Multi-Cpu/Core C++ Compiles in the Visual Studio Ide (2008)
How to Read System Information in C++
How to Initialize All Tuple Elements by the Same Arguments
Boost Serialization, Deserialization of Raw C Arrays
Why Derive from a Concrete Class Is a Poor Design
How to Check That I Didn't Break Anything When Refactoring
Dealing with Library Dependencies on Linux
Sdl/C++ Opengl Program, How to Stop Sdl from Catching Sigint