如何实例化COM dll [英] How to instantiate a COM dll
本文介绍了如何实例化COM dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家,
我想知道是否有任何方法来实例化除cocreateInstance及其变体之外的COM组件。
问候,
Vikas Mishra
解决方案
没有真正明智或安全的方法,但那里不在。基本上你可以自己做CoCreateInstance所做的事情。有很多步骤,我不知道它们全部用于它们但它们将包括在内。
用LoadLibrary加载Dll
使用GetProcAddress获取一个或多个函数指针到标准IClassFactory派生工厂类导出的函数
调用这些入口点创建一个班级工厂。
使用班级工厂创建CoClass的实例
按照与获取方式相反的顺序释放所有内容。
如果您需要更多详细信息,可以查看 Wine 源代码中CoCreateInstance
的实施情况>基于Linux或Cygwin构建的项目,并模拟包括COM的Win32 API。
非Windows平台还有其他开源COM实现CoCreateInstance
实现虽然它们可能过于简单,无法帮助您绕过真实的东西Windows。
创建一个COM
对象有一些''正确的方法''(Matthew很好地涵盖了''非官方方式'' )。您可以使用CoGetClassObject
并调用IClassFactory :: CreateInstance
。
MSDN的实例创建帮助函数 [ ^ ]显示其他可能性。
但是,我不知道你是否认为上述只是CoCreatInstance
''variants''。
如果必须将COM DLL视为COM对象,请参阅解决方案#1和#2。如果DLL不必被视为COM,那么您可以简单地链接到它并通过常规调用调用COM接口。您仍然会使用相同的编组,返回代码和异常处理技术,但您可以直接调用API而不是通过智能指针等。
Hi Experts,
I wanted to know if there is any way to instantiate a COM component other than cocreateInstance and its variant.
Regards,
Vikas Mishra
解决方案
There''s no really sensible or safe way but there is a way. Essentially you can do what CoCreateInstance does by yourself. There are a number of steps and I don''t know them all by heart but they will include.
Load the Dll withLoadLibrary
Get one or more function pointers to the functions exported by the standard IClassFactory derived factory class usingGetProcAddress
Call these entry points to create a class factory.
Use the class factory to create an instance of your CoClass
Free up everything in the reverse order from how you acquired it.
If you need more details you could look at the implementation ofCoCreateInstance
within the source of the Wine project which builds on Linux or under Cygwin and emulates the Win32 API including COM.
There are other open source COM implementations for non Windows platforms which will haveCoCreateInstance
implementations although they may be too simplified to help you much with bypassing the real thing on Windows.
There are some ''ufficial ways'' for creating aCOM
objects (Matthew covered well the ''unofficial ways''). You may useCoGetClassObject
and the call theIClassFactory::CreateInstance
.
MSDN''s Instance Creation Helper Functions[^] shows other possibilities.
However, I don''t know if you consider the above justCoCreatInstance
''variants''.
If the COM DLL has to be treated as a COM object, then see solutions #1 and #2. If the DLL does not have to be treated as COM, then you could simply link to it and call the COM interfaces via conventional calls. You would still use the same marshalling, return code and exception handling techniques, but you would call the APIs directly instead of going through smart pointers etc.
这篇关于如何实例化COM dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文