COM

  • Thread starter Thread starter Duncan Winn
  • Start date Start date
D

Duncan Winn

Does anyone know how to access a COM component from VC++ 7???

Thanks for any help, and sorry if this is an inappropriate place to post
this question, but I did not know which user group to post it on.
 
If the component includes a type library, you can import
the type library and use an interface pointer to access
methods. Something like this:
#import "MyComponent.dll" named_guids //import the dll

#include "MyComponent.tlh" //include the type library

Declare an interface pointer to the class:
MyCom::IComCls pMyCom;

Use the pointer to create an instance of the object
pMyCom.CreateInstance(MyCom::CLSID_CMyCom);

Use the pointer:
pMyCom->SomeWork(param1, param2);


If no type library, you can do the following:
#include "MyComponent_i.c"

IComClasPtr pMyCom; //define an interface pointer
HRESULT hr;

Use the pointer to create an instance of the object
hr = pMyCom.CreateInstance(CLSID_CMyCom);
//some code here to check if succeeded

Use the pointer:
hr = pMyCom->SomeWork(param1, param2);
 
chris said:
If the component includes a type library, you can import
the type library and use an interface pointer to access
methods. Something like this:
#import "MyComponent.dll" named_guids //import the dll

#include "MyComponent.tlh" //include the type library

You should never directly #include a .tlh file - the #import directive
already includes the file for you.

-cd
 
Back
Top