简体   繁体   中英

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 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++?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM