简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM