Get functions/objects of imported .tlb

2019-07-14 21:59发布

问题:

I've got a program which shipped with a .tlb file to access some functions/objects (read variables etc.) with my own C++ program. I did a search and imported the .tlb file with:

#import "MyLib.tlb" named_guids no_namespace

I can also import it by using the libid from oleview.exe (ProgId does not work).

Even if I get some warnings (as follows), my program still runs:

C4278 ['TextOut', 'CreateEvent', 'DeleteFile'] is already a macro; use the 'rename' qualifier

But.. how can I gain access of the functions/objects now? Sorry I'm a beginner so please be patient. Does it work somehow with IDispatch? Do I need to import some more dll's or do I need more #include directives?

I'm using Visual C++ 2008 Express.

--
Edit: Ok sorry, I already have access to the header of the objects (I see "Application" in auto completion) but I have no idea how to get the objects.

Object Overview

And I think I found the related wikipedia article.

回答1:

Importing type library gives you description of all the interfaces and identifiers of that library. Normally you should not include additionally any header files. You should just normally create these interfaces using COM smart pointer and call their methods:

CComPtr pInterface;
pInterface.CoCreateInstance(__uuidof("ClassNameFromTLB"));
pInterface->CallMethod();