ACTIVEX和OCX控件傳遞字符串給網頁上的JS


第一步:

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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM