Get functions/objects of imported .tlb

拥有回忆 提交于 2019-12-11 01:29:02

问题


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


来源:https://stackoverflow.com/questions/8396790/get-functions-objects-of-imported-tlb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!