Reputation: 29586
I'm trying to interface a library that exports an Automation compatible interface via a .TLB.
The TLB lists function
s 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 function
s from C++?
Upvotes: 1
Views: 214
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