第一步:
KSDLL2.idl文件中
dispinterface _DKSDLL2
{
properties:
methods:
[id(1)] void CheckIt();
[id(2)] BSTR GetIt();
};
第二步:
KSDLL2Ctrl.h文件中
protected:
void CheckIt(void);
BSTR GetIt();
第三步:
KSDLL2Ctrl.cpp文件中
// 调度映射
BEGIN_DISPATCH_MAP(CKSDLL2Ctrl, COleControl)
DISP_FUNCTION_ID(CKSDLL2Ctrl, "CheckIt", dispidCheckIt, CheckIt, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CKSDLL2Ctrl, "GetIt", dispidGetIt, GetIt, VT_BSTR, VTS_NONE)
END_DISPATCH_MAP()
第四步:
KSDLL2Ctrl.cpp文件中
BSTR CKSDLL2Ctrl::GetIt()
{
CString strmac;
strmac="12345123451234512345";
return strmac.AllocSysString();
}
第五步:
html文件中
var obj = document.getElementById("Object1");
var result = obj.GetIt();
alert(result);