从常规DLL(C ++)创建COM对象 [英] Creating a COM object from a regular DLL (C++)

查看:102
本文介绍了从常规DLL(C ++)创建COM对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C ++创建的常规DLL,可以从VBScript文件运行VBScript过程. DLL能够将变体字符串和safearray作为参数传递给脚本过程.但是,对于名称/值对的向量,我想通过将向量包装在COM类中并将其IDispatch指针作为参数传递给脚本,以将其传递给脚本过程.是否可以拥有一个COM类并在常规DLL中创建COM对象,然后将其IDispatch接口获取一个变量变量?如果是,怎么办(如果可能,请提供示例代码)?

I have a regular DLL created in C++ that can run VBScript procedures from a VBScript file. The DLL is able to pass variant strings and safearray as parameters to script procedures. However, for a vector of name-value pairs I want to pass it to the script procedure by wrapping the vector in a COM class and passing its IDispatch pointer as parameter to the script. Is it possible to have a COM class and create the COM object inside a regular DLL, and then get its IDispatch interface to a variant variable? If yes, how (sample codes if possible)?

推荐答案

我这样做了,没有一次.可以在www.ProSysLib.org上的ProSysLib中找到最后一个示例.

在这种情况下,您甚至不需要实现注册/注销例程.您只需要一个导出函数即可从DLL中返回接口的新实例.在ProSysLib中检查我的代码,它具有名为CreatePSLSystem的功能,您也可以在此处查看: http://prosyslib.org /src/ProSysLib.cpp.html

然后,您只需从客户端加载该DLL并调用该方法.它将帮助您查看名为StealthDeployment的VC ++ 2005示例.也可以在此处查看有关隐形部署"的概念: http://prosyslib.org/Help/webframe.html

它解释了如何在不注册的情况下使用COM.
I did this, and not once. The last example can be found in ProSysLib on www.ProSysLib.org

In this case you wouldn''t even need to implement register/unregister routines. You just need one export function that would return a new instance of you interface from within the DLL. Check my code in ProSysLib, it has function in it called CreatePSLSystem, which you can also see here: http://prosyslib.org/src/ProSysLib.cpp.html

And then you just load that DLL from your client and call that method. It will help you to see VC++ 2005 example called StealthDeployment. Also see about the concept of Stealth Deployment here: http://prosyslib.org/Help/webframe.html

It explains how to use COM without registration.


您可能能够在dll中实现DllRegisterServer和DllUnregisterServer,这将需要包含注册com组件的逻辑.听起来对我来说就像一场噩梦.

您最好创建一个单独的COM组件(带有ATL等),以使您现有的dll和vbscript都可以使用.
You might be able to implement DllRegisterServer and DllUnregisterServer in your dll, which would need to contain the logic for registering your com components. Sounds like a nightmare to me.

You might be better off creating a seperate COM component (with ATL, etc), that your existing dll and your vbscript could both use.


这篇关于从常规DLL(C ++)创建COM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆