1、使用vc的 MFC ActiveX ControllWinzad 做的一简单控件(无界面)
2、在html页面中使用。
问题:
1、ocx打包在一客户端程序(使用前需安装)安装包,客户端程序中将该ocx注册到用户注册表!!
这种方法与制作cab文件,自动下载是否一样效果??
2、如果1成立,则怎么将我的ocx让客户机认为是安全的?也就是当该ocx运行时不出现IE的安全提示!??
fool_leave(请及时结贴) 回复于 2005-02-28 09:36:06 得分 75
按照代码的注释要求修添加程序代码就可以避免上述的问题了。我的所有控件都是用该代码段,没有问题。
/****************
// 在ActiveX的类声明文件XXXCtrl.h的头部中添加如下代码
#include <objsafe.h>
// 在ActiveX的类声明文件C..Ctrl.h的类声明内部添加如下代码
// 接口映射
DECLARE_INTERFACE_MAP()
BEGIN_INTERFACE_PART(ObjSafe, IObjectSafety)
STDMETHOD_(HRESULT, GetInterfaceSafetyOptions) (
REFIID riid,
DWORD __RPC_FAR *pdwSupportedOptions,
DWORD __RPC_FAR *pdwEnabledOptions
);
STDMETHOD_(HRESULT, SetInterfaceSafetyOptions) (
REFIID riid,
DWORD dwOptionSetMask,
DWORD dwEnabledOptions
);
END_INTERFACE_PART(ObjSafe);
*********************************************** *******************/
/**********************
// 在ActiveX的类实现文件XXXCtrl.cpp中添加如下代码,并将CXXXCtrl更换为你的ActiveX的类名称
// IObjectSafety的接口映射
BEGIN_INTERFACE_MAP( CXXXCtrl, COleControl )
INTERFACE_PART(CXXXCtrl, IID_IObjectSafety, ObjSafe)
END_INTERFACE_MAP()
/
// IObjectSafety 成员函数
// AddRef, Release, QueryInterface
ULONG FAR EXPORT CXXXCtrl::XObjSafe::AddRef()
{
METHOD_PROLOGUE(CXXXCtrl, ObjSafe)
return pThis->ExternalAddRef();
}
ULONG FAR EXPORT CXXXCtrl::XObjSafe::Release()
{
METHOD_PROLOGUE(CXXXCtrl, ObjSafe)
return pThis->ExternalRelease();
}
HRESULT FAR EXPORT CXXXCtrl::XObjSafe::QueryInterface(
REFIID iid, void FAR* FAR* ppvObj)
{
METHOD_PROLOGUE(CXXXCtrl, ObjSafe)
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}
const DWORD dwSupportedBits =
INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA;
const DWORD dwNotSupportedBits = ~ dwSupportedBits;
/// //
// CXXXCtrl::XObjSafe::GetInterfaceSafetyOptions
HRESULT STDMETHODCALLTYPE
CXXXCtrl::XObjSafe::GetInterfaceSafetyOptions(
REFIID riid,
DWORD __RPC_FAR *pdwSupportedOptions,
DWORD __RPC_FAR *pdwEnabledOptions
)
{
METHOD_PROLOGUE(CXXXCtrl, ObjSafe)
HRESULT retval = ResultFromScode(S_OK);
// 接口是否存在
IUnknown FAR* punkInterface;
retval = pThis->ExternalQueryInterface(&riid, (void * *)&punkInterface);
if (retval != E_NOINTERFACE) // 接口存在
{
punkInterface->Release(); // 释放引用
}
// We support both kinds of safety and have always both set,
// regardless of interface.
*pdwSupportedOptions = *pdwEnabledOptions = dwSupportedBits;
return retval; // E_NOINTERFACE if QI failed
}
/
// CXXXCtrl::XObjSafe::SetInterfaceSafetyOptions
HRESULT STDMETHODCALLTYPE
CXXXCtrl::XObjSafe::SetInterfaceSafetyOptions(
REFIID riid,
DWORD dwOptionSetMask,
DWORD dwEnabledOptions
)
{
METHOD_PROLOGUE(CXXXCtrl, ObjSafe)
// 接口是否存在
IUnknown FAR* punkInterface;
pThis->ExternalQueryInterface(&riid, (void * *)&punkInterface);
if (punkInterface) // 接口存在
{
punkInterface->Release(); // 释放引用
}
else // 接口不存在
{
return ResultFromScode(E_NOINTERFACE);
}
// Can't set bits we don't support.
if (dwOptionSetMask & dwNotSupportedBits)
{
return ResultFromScode(E_FAIL);
}
// Can't set bits we do support to zero
dwEnabledOptions &= dwSupportedBits;
// (We already know there are no extra bits in mask. )
if ((dwOptionSetMask & dwEnabledOptions) != dwOptionSetMask)
{
return ResultFromScode(E_FAIL);
}
// Don't need to change anything since we're always safe.
return ResultFromScode(S_OK);
}