获取导入的.tlb的函数/对象 [英] Get functions/objects of imported .tlb
问题描述
我有一个程序,它附带一个.tlb文件来访问一些函数/对象(读取变量等)与我自己的C ++程序。我做了一个搜索并导入.tlb文件:
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
我也可以使用oleview.exe中的libid导入它(ProgId不工作)。
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
但是如何获取函数/对象的访问?
对不起,我是初学者,所以请耐心等待。
它以某种方式工作与IDispatch?我需要导入一些更多的dll或者需要更多的#include指令吗?
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?
我使用Visual C ++ 2008 Express。
I'm using Visual C++ 2008 Express.
-
编辑:对不起,我已经可以访问对象的标题(我在自动完成中看到应用程序),但我不知道如何获取对象。
--
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.
我想我发现相关的维基百科文章< a>。
And I think I found the related wikipedia article.
推荐答案
导入类型库给出了该库的所有接口和标识符的描述。通常你不应该包括额外的任何头文件。你应该通常使用COM智能指针创建这些接口并调用他们的方法:
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();
这篇关于获取导入的.tlb的函数/对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!