Html页面文件中调用OCX控件中带有BSTR参数的函数出错的问题(OCX控件由MFC ActiveX ControlWizard创建)

cameilla 2005-04-27 12:24:16
相关代码如下:

OCX控件对应的.odl文件
/******************
OCXTest_CalcPi.odl
控件有4个函数CalcPi,TestFunc,TestFunc2,AboutBox
,一个put属性Digits
*******************/

#include <olectl.h>
#include <idispids.h>

[ uuid(5424A731-F67B-446E-B584-3D0BAB54FEF3), version(1.0),
helpfile("OCXTest_CalcPi.hlp"),
helpstring("OCXTest_CalcPi ActiveX Control module"),
control ]
library OCXTEST_CALCPILib
{
importlib(STDOLE_TLB);
importlib(STDTYPE_TLB);

// Primary dispatch interface for COCXTest_CalcPiCtrl

[ uuid(2481EC56-2EBA-44A8-B7A2-1A7E27245B52),
helpstring("Dispatch interface for OCXTest_CalcPi Control"), hidden ]
dispinterface _DOCXTest_CalcPi
{
properties:
// NOTE - ClassWizard will maintain property information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_PROP(COCXTest_CalcPiCtrl)
[id(1), bindable] long Digits;
[id(0)] long _Digits;
//}}AFX_ODL_PROP

methods:
// NOTE - ClassWizard will maintain method information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_METHOD(COCXTest_CalcPiCtrl)
[id(2)] boolean CalcPi(BSTR* pbstrPi);
[id(3)] BSTR TestFunc();
[id(4)] BSTR TestFunc2(BSTR Text);
//}}AFX_ODL_METHOD

[id(DISPID_ABOUTBOX)] void AboutBox();
};

// Event dispatch interface for COCXTest_CalcPiCtrl

[ uuid(AFDD0CC3-BAD8-4BF9-9BC3-D35655547BF0),
helpstring("Event interface for OCXTest_CalcPi Control") ]
dispinterface _DOCXTest_CalcPiEvents
{
properties:
// Event interface has no properties

methods:
// NOTE - ClassWizard will maintain event information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_EVENT(COCXTest_CalcPiCtrl)
//}}AFX_ODL_EVENT
};

// Class information for COCXTest_CalcPiCtrl

[ uuid(FD931B4C-3FBC-40AE-AC1E-4150912C712F),
helpstring("OCXTest_CalcPi Control"), control ]
coclass OCXTest_CalcPi
{
[default] dispinterface _DOCXTest_CalcPi;
[default, source] dispinterface _DOCXTest_CalcPiEvents;
};


//{{AFX_APPEND_ODL}}
//}}AFX_APPEND_ODL}}
};


/************************
COCXTest_CalcPiCtrl.cpp中
TestFunc()和TestFunc2()两个函数的实现代码
*************************/


BSTR COCXTest_CalcPiCtrl::TestFunc()
{
CString strResult;
// TODO: Add your dispatch handler code here
strResult=OLESTR("asdfasdfasdf");
return strResult.AllocSysString();
}

BSTR COCXTest_CalcPiCtrl::TestFunc2(BSTR Text)
{
CString strResult;
// TODO: Add your dispatch handler code here
strResult=OLESTR("qweqrqwerqwer");
return strResult.AllocSysString();
}

/*******************
测试此控件的html文件代码
*******************/
<HTML>
<HEAD>
<TITLE>test page for object OCXTest_CalcPi</TITLE>
</HEAD>
<BODY>
<object classid="clsid:FD931B4C-3FBC-40AE-AC1E-4150912C712F"
name=objocx
height="0" width="0" >
</object>

<script language= "VBScript">
dim RetTxt2
dim pText AS String
pText = "111"
RetTxt2 = objocx.TestFunc2 pText
document.write "Return Text by TestFunc2 is: " & RetTxt2

'following commented code can run correctly
'dim RetTxt
'RetTxt = objocx.TestFunc
'document.write "Return Text by TestFunc is: " & RetTxt

</script>
</BODY>
</HTML>

现象:
Html文件中调用OCXTest_CalcPi中的TestFunc函数,运行正常,
页面显示"Return Text by TestFunc is:asdfasdfasdf"字符串;
而调用带有BSTR参数的TestFunc2函数,页面却没有任何反映。
...全文
453 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoyuzi 2005-04-30
  • 打赏
  • 举报
回复
RetTxt2 = objocx.TestFunc2 pText改成RetTxt2 = objocx.TestFunc2(pText)呢,vb要有返回值应该加括号的,vbscript应该也是这样吧
mtgh 2005-04-29
  • 打赏
  • 举报
回复
把BSTR换成LPCTSTR 就可以了
xift_2008 2005-04-29
  • 打赏
  • 举报
回复
不是很懂,关注!
ysbcg 2005-04-27
  • 打赏
  • 举报
回复
... 帮你顶一下吧

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧