I'm still using Visual Studio 2005 for some C++ development. Thanks to ATL, I can use any COM component with modest amount of coding. For example, I can simply use #import directive to make a COM component accessible from my C++ code, then use CComPtr for easy access (and don't need to worry about releasing it, as it is an auto pointer).
#import directive takes DLL, ProgID, TLB, etc. This is fine when you use a third-party component, or a component outside of your solution. But I wonder why it doesn't take IDL file (I may be missing something here).
But if there's a COM component project within a solution, and you try to use the COM component from a project within the same solution, #import may not be handy. I don't want to write a code like this.
#import "..\MyComComponent\Release\MyComComponent.dll" no_namespace
The dll file is created under release or debug sub folders. Tlb is the same. I can use ProgID, but I tend to forget what it is.
Because IDL file is accessible, why can't #import take this? Well, the reason may be because you don't need to. I stumbled here.
The COM project automatically creates a header file from the IDL. All I needed to do was to include the header file generated. In the case above, the COM project must have created MyComComponent.h (and MyComCOmponent_i.c). From a project in the solution, it can be included like this.
include "..\MyComComponent\MyComComponent.h"
This look much more elegant than using #import with release/debug sub folders.

新しいコメントの投稿