博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Using ActiveX in IE
阅读量:5225 次
发布时间:2019-06-14

本文共 5005 字,大约阅读时间需要 16 分钟。

Method 1:

1.Import the ActiveX Control in html.

       	  	  	  

Class Id is a unique identity of ActiveX. 

2.JavaScript jude if the ActiveX Control is existing.

Method 2:

3.Create ActiveX object using new ActiveXObject in javascript.

var activexObj = new ActiveXObject("ArchiveManage.ArchiveManageCtrl.1");

The argument of ActiveXObject is progId, not classId.

3.Resove ActiveX security warning.

Step1:Replace html header.

Step2:Include 
<objsafe.h> in control implement.

#include 
Step3:Add declared in ActiveX Control header file.

//去掉安全警告 BEGIN	DECLARE_INTERFACE_MAP()	BEGIN_INTERFACE_PART(ObjectSafety, IObjectSafety)		STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD __RPC_FAR *pdwSupportedOptions, DWORD __RPC_FAR *pdwEnabledOptions);		STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions);	END_INTERFACE_PART(ObjectSafety)//去掉安全警告 END
Step4:Add following code in implement file.

//去掉安全警告 BEGINBEGIN_INTERFACE_MAP(CWebPhoneCtrl, COleControl)INTERFACE_PART(CWebPhoneCtrl, IID_IObjectSafety, ObjectSafety)END_INTERFACE_MAP()// Implementation of IObjectSafetySTDMETHODIMP CWebPhoneCtrl::XObjectSafety::GetInterfaceSafetyOptions(																																		 REFIID riid,																																		 DWORD __RPC_FAR *pdwSupportedOptions,																																		 DWORD __RPC_FAR *pdwEnabledOptions){	METHOD_PROLOGUE_EX(CWebPhoneCtrl, ObjectSafety)				if (!pdwSupportedOptions || !pdwEnabledOptions)		{			return E_POINTER;		}				*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;		*pdwEnabledOptions = 0;				if (NULL == pThis->GetInterface(&riid))		{			TRACE("Requested interface is not supported./n");			return E_NOINTERFACE;		}				// What interface is being checked out anyhow?		OLECHAR szGUID[39];		int i = StringFromGUID2(riid, szGUID, 39);				if (riid == IID_IDispatch)		{			// Client wants to know if object is safe for scripting			*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;			return S_OK;		}		else if (riid == IID_IPersistPropertyBag			|| riid == IID_IPersistStreamInit			|| riid == IID_IPersistStorage			|| riid == IID_IPersistMemory)		{			// Those are the persistence interfaces COleControl derived controls support			// as indicated in AFXCTL.H			// Client wants to know if object is safe for initializing from persistent data			*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;			return S_OK;		}		else		{			// Find out what interface this is, and decide what options to enable			TRACE("We didn't account for the safety of this interface, and it's one we support.../n");			return E_NOINTERFACE;		} }STDMETHODIMP CWebPhoneCtrl::XObjectSafety::SetInterfaceSafetyOptions(																																		 REFIID riid,																																		 DWORD dwOptionSetMask,																																		 DWORD dwEnabledOptions){	METHOD_PROLOGUE_EX(CWebPhoneCtrl, ObjectSafety)				OLECHAR szGUID[39];	// What is this interface anyway?	// We can do a quick lookup in the registry under HKEY_CLASSES_ROOT/Interface	int i = StringFromGUID2(riid, szGUID, 39);		if (0 == dwOptionSetMask && 0 == dwEnabledOptions)	{		// the control certainly supports NO requests through the specified interface		// so it's safe to return S_OK even if the interface isn't supported.		return S_OK;	}		// Do we support the specified interface?	if (NULL == pThis->GetInterface(&riid))	{		TRACE1("%s is not support./n", szGUID);		return E_FAIL;	}			if (riid == IID_IDispatch)	{		TRACE("Client asking if it's safe to call through IDispatch./n");		TRACE("In other words, is the control safe for scripting?/n");		if (INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwEnabledOptions)		{			return S_OK;		}		else		{			return E_FAIL;		}	}	else if (riid == IID_IPersistPropertyBag    || riid == IID_IPersistStreamInit    || riid == IID_IPersistStorage    || riid == IID_IPersistMemory)	{		TRACE("Client asking if it's safe to call through IPersist*./n");		TRACE("In other words, is the control safe for initializing from persistent data?/n");				if (INTERFACESAFE_FOR_UNTRUSTED_DATA == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_DATA == dwEnabledOptions)		{			return NOERROR;		}		else		{			return E_FAIL;		}	}	else	{		TRACE1("We didn't account for the safety of %s, and it's one we support.../n", szGUID);		return E_FAIL;	}}STDMETHODIMP_(ULONG) CWebPhoneCtrl::XObjectSafety::AddRef(){	METHOD_PROLOGUE_EX_(CWebPhoneCtrl, ObjectSafety)		return (ULONG)pThis->ExternalAddRef();}STDMETHODIMP_(ULONG) CWebPhoneCtrl::XObjectSafety::Release(){	METHOD_PROLOGUE_EX_(CWebPhoneCtrl, ObjectSafety)		return (ULONG)pThis->ExternalRelease();}STDMETHODIMP CWebPhoneCtrl::XObjectSafety::QueryInterface(																													REFIID iid, LPVOID* ppvObj){	METHOD_PROLOGUE_EX_(CWebPhoneCtrl, ObjectSafety)		return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);}//去掉安全警告 END

转载于:https://www.cnblogs.com/yefengmeander/archive/2012/11/23/2887563.html

你可能感兴趣的文章
Leetcode: Unique Binary Search Trees II
查看>>
C++ FFLIB 之FFDB: 使用 Mysql&Sqlite 实现CRUD
查看>>
Spring-hibernate整合
查看>>
c++ map
查看>>
exit和return的区别
查看>>
js += 含义(小知识)
查看>>
B2321 [BeiJing2011集训]星器 数学&&物理
查看>>
201571030319 四则运算
查看>>
RestTemplate 调用本地服务 connection refused
查看>>
.NET方向高级开发人员面试时应该事先考虑的问题
查看>>
台达PLC modbus 不支持04功能码
查看>>
发布一个JavaScript工具类库jutil,欢迎使用,欢迎补充,欢迎挑错!
查看>>
discuz 常用脚本格式化数据
查看>>
MS CRM 2011 创建基于Fetch的报表 -- 进阶版
查看>>
洛谷P2777
查看>>
PHPStorm2017设置字体与设置浏览器访问
查看>>
SQL查询总结 - wanglei
查看>>
安装cocoa pods时出现Operation not permitted - /usr/bin/xcodeproj的问题
查看>>
makefile中使用变量
查看>>
GIT笔记:将项目发布到码云
查看>>