如何从经典 ASP 调用 COM 对象函数
在我的经典 ASP 站点中,我需要调用 COM 对象函数。
这是 COM 组件定义:
interface IMyComponent : IDispatch
{
HRESULT GetVersion([in] int, [out] double*, [out] BSTR*);
}
在服务器端,我创建组件对象并尝试调用“GetVersion”函数:
<%
Dim app
Set app = CreateObject("MyComponent")
Dim someUsefulValue
Dim version
app.GetVersion 1, someUsefulValue, version
%>
但是此代码失败,并出现错误“类型不匹配”。 我应该如何调用这个函数?
In my classic ASP site I need to call COM object function.
Here is the COM component definition:
interface IMyComponent : IDispatch
{
HRESULT GetVersion([in] int, [out] double*, [out] BSTR*);
}
In server side I create component object and try to call 'GetVersion' function:
<%
Dim app
Set app = CreateObject("MyComponent")
Dim someUsefulValue
Dim version
app.GetVersion 1, someUsefulValue, version
%>
But this code fails with error "Type mismatch".
How I should call this function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,请记住,没有其他浏览器支持 ActiveX,而不是 Internet Explorer,因此我会重新考虑是否不应该采用其他方法来解决问题,也许使用其他更有效的组件向其他浏览器开放...
例如 Microsoft Silverlight(如果您采用 .NET 方式)、Adobe Flash、Shockwave、空中...
HTML
您的 ASP 页面需要有 ActiveX 的
然后你就可以充当普通的 DOM 对象
first of all, keep in mind that no other browser supports ActiveX rather than Internet Explorer, so I would re-think if you shouldn't get other approach to the problem, maybe using other component that is more open to other browsers...
like Microsoft Silverlight (if you are going the .NET way), Adobe Flash, Shockwave, Air...
in HTML
Your ASP page needs to have the
<object>
code of your ActiveXthen you just act as a normal DOM object
将 COM 方法的第一个参数的类型更改为 long,而不是 int。 Long 转换为变体类型 VT_I4,而 int 转换为 VT_INT。如果我没记错的话,VBScript 无法识别 VT_INT,因为它不是“自动化兼容类型”(int 的大小可能无法跨编译器/平台固定!)
Change the type of first parameter of the COM method to long, rather than int. Long translates to the variant type VT_I4, while int translates to VT_INT. If memory serves me right, VBScript doesn't recognize VT_INT as it's not an "automation compatible type" (the size of int may not be fixed across compilers/platforms!)
尝试:
在服务器端,您应该使用 Server.CreateObject,而不仅仅是 CreateObject,因为它通常用于客户端 VBScript。
确保已使用 regsvr32 MyComponent.dll 安装并注册 COM 对象
Try:
On the server side you should use Server.CreateObject, not just CreateObject as it is normally used for client side VBScript.
Make sure the COM object has been installed and registered using regsvr32 MyComponent.dll