C++빌더에서 보안경고 없애기
빌더버젼 : 5.0
델파이 5.0 프로그래밍 바이블의 편저자 이신 정우철님 께서 답변해 주신 내용을 조금 수정하였습니다.
원 소스는 5.0 이하버젼용 인듯 합니다. 그리고 파라메터 받는 부분은 설명하지 않겠습니다..^^;
빌더 5.0 에는 IObjectSafety의 내부변수인 m_dwSafety 가 정의 되어있지 않더군요..
(3.0에는 되어 있었습니다 )
그래서 제 클래스에 DWORD m_dwSafety 를 정의해주니 잘 되더군요..무슨얘기냐구여 ? 인제 시작하죠..
Activex 폼을 만들면 생기는 ....Impl.h 파일에
class ATL_NO_VTABLE TEnerpiaClientMainImpl:
VCLCONTROL_IMPL( TEnerpiaClientMainImpl, EnerpiaClientMain, TEnerpiaClientMain,
IEnerpiaClientMain, DIID_IEnerpiaClientMainEvents)
{
.
.
.
이런 구문이 있죠 ? 여기에 두개의 클래스를 추가해 줍니다..
class ATL_NO_VTABLE TEnerpiaClientMainImpl:
VCLCONTROL_IMPL( TEnerpiaClientMainImpl, EnerpiaClientMain, TEnerpiaClientMain,
IEnerpiaClientMain, DIID_IEnerpiaClientMainEvents),
public IPersistPropertyBagImpl<TEnerpiaClientMainImpl>, // <----- 파라메터를 받기위해
public IObjectSafetyImpl<TEnerpiaClientMainImpl,INTERFACESAFE_FOR_UNTRUSTED_CALLER> // 문제의 보안경고 메시지를 없애기위해..
{
.
.
.
위의 구문을 보시고 적당히 수정하시면 됩니다..
INTERFACESAFE_FOR_UNTRUSTED_CALLER - 요거는 액티브 X 스크립트 요청에 대한 것 이라는걸 지정하는 거랍니다.
자세한 설명은 빌더 디렉토리의 include/objsafe.h 에서 IObjectSafety 로 찾아보시면 설명이 있습니다.
위와같이 만드신후 바로아래의 public 절에 변수를 하나 만들어줍니다..
(빌더 5.0에만 적용됩니다..그이하버젼에서는 추가하신후에 에러나면 지워주세요 ^^;)
public:
DWORD m_dwSafety;
그다음 .....
조금 내려가시면 BEGIN_COM_MAP 부분에 아래 화살표 부분을 넣어주세요..바꾸실거 없습니다..걍 복사..!!
BEGIN_COM_MAP(TEnerpiaClientMainImpl)
VCL_CONTROL_COM_INTERFACE_ENTRIES(IEnerpiaClientMain)
COM_INTERFACE_ENTRY_IMPL(IPersistPropertyBag) <---- 파라메터 받기위해...
COM_INTERFACE_ENTRY(IObjectSafety) <----
END_COM_MAP()
이제 50% 끝났습니다..^^;
다음 protected 절에 메소드를 추가합니다..그대루 복사해다 넣으세요..
STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid,
DWORD *pdwSupportedOptions,
DWORD *pdwEnabledOptions) {
ATLTRACE(_T("CObjectSafetyImpl::GetInterfaceSafetyOptions\n"));
if (!pdwSupportedOptions || !pdwEnabledOptions) return E_FAIL;
LPUNKNOWN pUnk;
if (_InternalQueryInterface (riid, (void**)&pUnk) == E_NOINTERFACE) {
// Our object doesn't even support this interface.
return E_NOINTERFACE;
}
else{ // Cleanup after ourselves.
pUnk->Release();
pUnk = NULL;
}
if (riid == IID_IDispatch) {
// IDispatch is an interface used for scripting. If your
// control supports other IDispatch or Dual interfaces, you
// may decide to add them here as well. Client wants to know
// if object is safe for scripting. Only indicate safe for
// scripting when the interface is safe.
*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
*pdwEnabledOptions = m_dwSafety &
INTERFACESAFE_FOR_UNTRUSTED_CALLER;
return S_OK;
}else if ((riid == IID_IPersistStreamInit) ||
(riid == IID_IPersistStorage)) {
// IID_IPersistStreamInit and IID_IPersistStorage are
// interfaces used for Initialization. If your control
// supports other Persistence interfaces, you may decide to
// add them here as well. Client wants to know if object is
// safe for initializing. Only indicate safe for initializing
// when the interface is safe.
*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;
*pdwEnabledOptions = m_dwSafety & INTERFACESAFE_FOR_UNTRUSTED_DATA;
return S_OK;
} else { // We are saying that no other interfaces in this control are
// safe for initializing or scripting.
*pdwSupportedOptions = 0;
*pdwEnabledOptions = 0;
return E_FAIL;
}
}
STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid,
DWORD dwOptionSetMask,
DWORD dwEnabledOptions) {
ATLTRACE(_T("CObjectSafetyImpl::SetInterfaceSafetyOptions\n"));
if (!dwOptionSetMask && !dwEnabledOptions)
return E_FAIL;
LPUNKNOWN pUnk;
if (_InternalQueryInterface (riid, (void**)&pUnk) == E_NOINTERFACE) {
// Our object doesn't even support this interface.
return E_NOINTERFACE; }else{ // Cleanup after ourselves.
pUnk->Release();
pUnk = NULL;
}
// Store our current safety level to return in
// GetInterfaceSafetyOptions
m_dwSafety |= dwEnabledOptions & dwOptionSetMask;
if ((riid == IID_IDispatch) &&
(m_dwSafety & INTERFACESAFE_FOR_UNTRUSTED_CALLER)) {
// Client wants us to disable any functionality that would
// make the control unsafe for scripting. The same applies to
// any other IDispatch or Dual interfaces your control may
// support. Because our control is safe for scripting by
// default we just return S_OK.
return S_OK;
}else if (((riid == IID_IPersistStreamInit) ||
(riid == IID_IPersistStorage)) &&
(m_dwSafety & INTERFACESAFE_FOR_UNTRUSTED_DATA)) {
// Client wants us to make the control safe for initializing
// from persistent data. For these interfaces, this control
// is safe so we return S_OK. For Any interfaces that are not
// safe, we would return E_FAIL. return S_OK; }else{
// This control doesn't allow Initialization or Scripting
// from any other interfaces so return E_FAIL.
return E_FAIL;
}
}
------------------------
요기까지 복사 해놓으시고...!!!
저장하시고 컴파일 !!!
다됬습니다...
이제 스크립트 보안메시지는 안나올겁니다..(물론 ocx에서 파라메타를 안받는다면 원래 안나오구요 ^^; )
아..그리구...인터넷 옵션에서 보안->"안전한것으로 표시된 Activex 컨트롤 스크립트" 요건 당근 "사용"
으루 되어 있어야 겠죠 ?
|