1,新建mfc activeX控件 ,全部默认
2,类视图 右键xxxlib下面的xxxevents 添加方法 返回类型选择void
参数选择LONG BSTR 选择添加
typedef int (_stdcall * GWQPlayVoice)(int iPortNo ,char *strVoice);//定义函数指针类型
void CActiveXCtrl::GWQ_PlayVoice(LONG iCom, LPCTSTR strVoice)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HINSTANCE hInst;
GWQPlayVoice App_GWQ_PlayVoice;
int iRet = 0;
hInst=LoadLibrary(_T("liboutclearsqb_anzhentong.dll"));//动态加载Dll
App_GWQ_PlayVoice=(GWQPlayVoice)GetProcAddress(hInst,"GWQ_PlayVoice");//获取Dll的导出函数
if(!App_GWQ_PlayVoice)
{
MessageBox(_T("获取Add函数地址失败!"));
}
iRet=App_GWQ_PlayVoice( iCom, (char *)strVoice);
if (iRet==0)
{
MessageBox(_T("成功!"));
}
else
{
MessageBox(_T("失败!"));
}
// TODO: 在此添加调度处理程序代码
}
3,注册 regsvr32 ***.ocx
4,将dll放在windows下面
5,编写网页
<OBJECT ID="ActiveX" WIDTH="100" HEIGHT="50" CLASSID="CLSID:5ACEFCA5-7285-40E4-94A3-16E99E8CCFBF">
</OBJECT>
//响应OCX控件的TestEvent1事件
<script language="javascript" for="ActiveX" event="TestEvent1(nVar)">
alert("Event_TestEvent1 Param_nVar is:" + String(nVar));
</script>
//调用OCX控件的showInput函数的javascript函数
<script language="javascript">
function Show(varStr)
{
alert("提示信息!21111");
ActiveX.GWQ_PlayVoice(0,"中国人民解放军");
alert("提示信息!122222");
}
</script>
//html代码
</br></br>
<a href="javascript:Show('大家好!')" >调用OCX的showInput方法</a>