ActiveX를 만들었는데, 레지스트리나 시스템 파일 등...의 기능이 포함되어 있을 경우,
" 이 페이지의 ActiveX 컨트롤이 다른 부분과 상호 작용하는데 안전하지 않을 수 있습니다.
상호 작용을 허용하시겠습니까? "
와 같은 메시지가 뜨게 됩니다.
이 경우,
아래와 같이 안정성 처리(IObjectSafety)를 추가해줘야 합니다.
1. Ctrl 클래스의 헤더파일(h)에 추가해줍니다.
: 색으로 표시된 부분 과감히 CTRL+C, CTRL+V 하시면 됩니다. ^^;... (MS 문서 참조)
#include <objsafe.h>
class CTestCtrl : public COleControl
{
//////////////////////////////////////////////////////////////////////////
// EOCS_2010_0217 : IObjectSafety 처리 추가
DECLARE_INTERFACE_MAP()
BEGIN_INTERFACE_PART(ObjSafe, IObjectSafety)
STDMETHOD_(HRESULT, GetInterfaceSafetyOptions) (
/* [in] */ REFIID riid,
/* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
/* [out] */ DWORD __RPC_FAR *pdwEnabledOptions
);
STDMETHOD_(HRESULT, SetInterfaceSafetyOptions) (
/* [in] */ REFIID riid,
/* [in] */ DWORD dwOptionSetMask,
/* [in] */ DWORD dwEnabledOptions
);
END_INTERFACE_PART(ObjSafe);
// Constructor
public:
.
.
.
2. Ctrl 클래스의 소스파일(cpp)에 추가해줍니다.
: 색으로 표시된 부분 과감히 CTRL+C, CTRL+V 하시면 됩니다. ^^;... (MS 문서 참조)
. MS 자료나 인터넷이나 다 이렇게 정형화(?) 되어 있습니다.
/////////////////////////////////////////////////////////////
// Interface map for IObjectSafety
BEGIN_INTERFACE_MAP( CTestCtrl, COleControl )
INTERFACE_PART(CTestCtrl, IID_IObjectSafety, ObjSafe)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////
// IObjectSafety member functions
ULONG FAR EXPORT CTestCtrl::XObjSafe::AddRef()
{
METHOD_PROLOGUE(CTestCtrl, ObjSafe)
return pThis->ExternalAddRef();
}
ULONG FAR EXPORT CTestCtrl::XObjSafe::Release()
{
METHOD_PROLOGUE(CTestCtrl, ObjSafe)
return pThis->ExternalRelease();
}
HRESULT FAR EXPORT CTestCtrl::XObjSafe::QueryInterface(
REFIID iid, void FAR* FAR* ppvObj)
{
METHOD_PROLOGUE(CTestCtrl, ObjSafe)
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}
const DWORD dwSupportedBits =
INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA;
const DWORD dwNotSupportedBits = ~ dwSupportedBits;
HRESULT STDMETHODCALLTYPE
CTestCtrl::XObjSafe::GetInterfaceSafetyOptions(
/* [in] */ REFIID riid,
/* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
/* [out] */ DWORD __RPC_FAR *pdwEnabledOptions)
{
METHOD_PROLOGUE(CTestCtrl, ObjSafe)
HRESULT retval = ResultFromScode(S_OK);
// does interface exist?
IUnknown FAR* punkInterface;
retval = pThis->ExternalQueryInterface(&riid,
(void * *)&punkInterface);
if (retval != E_NOINTERFACE) { // interface exists
punkInterface->Release(); // release it--just checking!
}
// we support both kinds of safety and have always both set,
// regardless of interface
*pdwSupportedOptions = *pdwEnabledOptions = dwSupportedBits;
return retval; // E_NOINTERFACE if QI failed
}
HRESULT STDMETHODCALLTYPE
CTestCtrl::XObjSafe::SetInterfaceSafetyOptions(
/* [in] */ REFIID riid,
/* [in] */ DWORD dwOptionSetMask,
/* [in] */ DWORD dwEnabledOptions)
{
METHOD_PROLOGUE(CTestCtrl, ObjSafe)
// does interface exist?
IUnknown FAR* punkInterface;
pThis->ExternalQueryInterface(&riid,
(void**)&punkInterface);
if (punkInterface) { // interface exists
punkInterface->Release(); // release it--just checking!
}
else { // interface doesn't exist
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);
}