Search code examples
c++comatl

How to include a COM Interface that is defined in another type library (or COM server DLL)


All

My Environment: Using VS C++ 2005, with ATL

I have project where I want create and build 2 separate COM server Dlls and I need to reference the interface of COM object defined in project A in project B. Note: I need to be able to do this at the IDL level, then the compiler will generate correct headers, etc. and my type library will be correct.

Here's an Example:

Project A:

Server Object -> IServer

Project B

Client Object -> IClient which has a method GetServer() that returns IServer defined in Project A

Project A is separate COM Dll and is build first. Project B is separate COM Dll and references Interface defined in project A.

Yes, I know, I can have IClient.GetServer() return the reference to server object as IUnknown and then have the developer explicitly cast it to the server interface but that's annoying and error prone.


Solution

  • As suggested, use importlib, but in my case I needed to use import in my idl. Also, the MIDL will generate #include in your header to the included header file from the other project for which you need to add include directory reference in your project properties since the header is in different folder.