Simon Richter
Simon Richter

Reputation: 29586

Initial Object Reference for OLE Automation Object with constructor

I'm trying to interface a library that exports an Automation compatible interface via a .TLB.

The TLB lists functions inside the interfaces to retrieve object references; the .TLH includes these as nonstatic member functions, which makes it difficult for me to call them without an object reference; thus, I have a bit of a chicken-and-egg problem here.

What is the correct way to invoke functions from C++?

Upvotes: 1

Views: 214

Answers (1)

sharptooth
sharptooth

Reputation: 170499

Use #import on the .tlb file, then use CreateInstance() method of an appropriate smart pointer type to instantiate the object, then just call member functions.

Something like this (error handling omitted):

 #import ThatTlbFile.tlb

 //at some point in your code you have to init COM
 CoInitialize(0);

 // once COM is initialized
 IInterfaceOfInterestPtr object;
 // this will ask COM to instantiate an object    
 object.CreateInstance( __uuidof( ComClassOfInterest ) );
 object->CallMethod();

Upvotes: 0

Related Questions