How to access COM component within a project

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.

新しいコメントの投稿

このフィールドの内容は非公開にされ、公表されることはありません。
  • ウェブページアドレスとメールアドレスは、自動的にハイパーリンクに変換されます。
  • 使用できるHTMLタグ: <a> <em> <strong> <code> <cite> <ul> <ol> <li> <dl> <dt> <dd> <p>
  • 行と段落は自動的に折り返されます。
  • Amazon製品へのリンクを次の形式で作成することが出来ます。[amazon product_id inline|full|thumbnail]. 例: [amazon 1590597559 thumbnail]
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • 画像を追加することが出来ます。

書式オプションに関するより詳しい情報...

認証コード
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
画像で表示されている数字および記号を入力してください。