在C ++控制台应用程序中使用COM dll [英] using COM dll in a c++ console application
本文介绍了在C ++控制台应用程序中使用COM dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人
我有一个包含COM METHOD函数的dll,并且我想在c ++控制台应用程序中使用这些函数.
请你能帮我吗
我只有DLL文件,没有其他文件(源代码,清单,............)
我使用Visual Studio 2010
在此先感谢
dear all
i have a dll that contain a COM METHOD functions and i want to use these functions in a c++ console application i searched alot for a tutorial or something to help me but nothing
please can you help me in this
i only have the DLL file no other files(source codes,manifest,............)
i use visual studio 2010
thanks in advance
推荐答案
您正在编写控制台应用程序这一事实应该是无关紧要的.您要实例化一个COM对象并调用一个方法.
您可以用困难的方式做到这一点, [ ^ ]或让IDE帮助您. [ [ ^ ]
The fact that you''re writing a console application should be irrelevent. You want to instantiate a COM object and invoke a method.
You can do it the hard way,[^] or let the IDE help you out.[^]
You don''t say if you''re using managed or unmanaged C++ which will make a big difference, so I can''t really point you to a tutorial, but here''s a start.[^]
如果其中嵌入了类型库,则相当容易
if it''s got a type library embedded in it, it''s fairly easy
// get ATL''s client templates
#include <atlcomcli.h>
// import the typelibrary direct from the dll
#import "<name of your com dll here>" raw_interfaces_only no_namespace
这将在您的输出目录中创建一个.tlh文件-查看对象和接口声明的文件
然后使用该com对象
That will create a .tlh file in your output directory - have a look at that for the object and interface declaration
then to use that com object
// declare com ptr
CComPtr<IwhateverTheInterfaceIs> comInterfacePtr;
// cocreate an instance
comInterfacePtr.CoCreateInstance(__uuidof(theCoClassFromTLHfile))
// then use methods
comInterfacePtr->Method()
这篇关于在C ++控制台应用程序中使用COM dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文