导航
  • 主页
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

:----------------- 英雄~~~~~~~~~~~~~~~~给我一段完整的关于IObjectSafety的代码成么---------------------------------

richincsdn2 2001-09-01 02:40:53

有支持IObjectSafety接口的程序给俺email一份好吗,谢谢
...全文
67 点赞 收藏 9
写回复
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongge 2002-05-28
参照以下进行更改,轻松解决。其中中文注释部分是必须加入的。
class CSign :
public IDispatchImpl<ISign, &IID_ISign, &LIBID_SIGNHANDLELib>,
public IObjectSafetyImpl<CSign,INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA>, // 加入继承ATL 版的
// IObjectSafety接口
public ISupportErrorInfo,
//public IObjectSafety,
public CComObjectRoot,
public CComCoClass<CSign,&CLSID_Sign>
{
public:
DWORD m_dwSafety;
public:
CSign() {}
BEGIN_COM_MAP(CSign)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISign)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(IObjectSafety) // 连接IObjectSafety
// 到这个COM map

END_COM_MAP()


//DECLARE_NOT_AGGREGATABLE(CSign)
// Remove the comment from the line above if you don't want your object to
// support aggregation.

DECLARE_REGISTRY_RESOURCEID(IDR_Sign)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid,
DWORD *pdwSupportedOptions,
DWORD *pdwEnabledOptions)//重载虚函数GetInterfaceSafetyOptions
{
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)//重载虚函数SetInterfaceSafetyOptions
{
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;
}
}
回复
richincsdn2 2001-09-02
up
回复
蒋晟 2001-09-02
msdn.microsoft.com
回复
蒋晟 2001-09-02
搜MSDN
回复
richincsdn2 2001-09-01
Internet/Intranet/Extranet Services SDK 那里有的下呢?
回复
蒋晟 2001-09-01
For More Information See the Internet/Intranet/Extranet Services SDK at SDK on Microsoft's Web site for more information on the IObjectSafety interface. An IObjectSafety sample application can be found in the Samples directory.

回复
richincsdn2 2001-09-01
啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!啊,这个不是啊!!!!!!!!!!!!!!!!
回复
蒋晟 2001-09-01
HOWTO: Mark MFC Controls Safe for Scripting/Initialization
ID: Q161873


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0, 6.0
Microsoft Internet Client Software Development Kit (SDK) version 4.0, 4.01
Microsoft Internet Explorer (Programming) versions 4.0, 4.01

--------------------------------------------------------------------------------


SUMMARY
By default, MFC ActiveX controls are not marked as Safe for Scripting and/or Safe for Initialization. This becomes apparent when the control is run in the Internet Explorer with the security level set to medium or high. In either of these modes, warnings may be displayed that the control's data is not safe or that the control may not be safe for scripts to use.

There are two methods that a control can use to eliminate these errors. The first involves the control implementing the IObjectSafety interface and is useful for controls that would like to change their behavior and become "safe" if run in the context of an Internet Browser. The second involves modifying the control's DllRegisterServer function to mark the control "safe" in the registry. This article covers the second of these methods. The first method, implementing the IObjectSafety interface, is covered in the Internet Client SDK.

Please keep in mind that a control should only be marked as safe if it is, in fact, safe. Please refer to the Internet Client SDK documentation for a description of this. See "Safe Initialization and Scripting for ActiveX Controls" under the Component Development Section.

NOTE: This article does not cover how to mark a control safe for downloading. For more information on code download and code signing, please refer to the Internet Client SDK.



MORE INFORMATION
Follow these steps to mark your MFC ActiveX Control as Safe for Scripting and Safe for Initializing:



Implement the CreateComponentCategory and RegisterCLSIDInCategory helper functions by adding the following cathelp.h and cathelp.cpp files to your project.
CATHELP.H

#include "comcat.h"

// Helper function to create a component category and associated
// description
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription);

// Helper function to register a CLSID as belonging to a component
// category
HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
CATHELP.CPP

#include "comcat.h"

// Helper function to create a component category and associated
// description
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
{
ICatRegister* pcr = NULL ;
HRESULT hr = S_OK ;

hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICatRegister,
(void**)&pcr);
if (FAILED(hr))
return hr;

// Make sure the HKCR\Component Categories\{..catid...}
// key is registered
CATEGORYINFO catinfo;
catinfo.catid = catid;
catinfo.lcid = 0x0409 ; // english

// Make sure the provided description is not too long.
// Only copy the first 127 characters if it is
int len = wcslen(catDescription);
if (len>127)
len = 127;
wcsncpy(catinfo.szDescription, catDescription, len);
// Make sure the description is null terminated
catinfo.szDescription[len] = '\0';

hr = pcr->RegisterCategories(1, &catinfo);
pcr->Release();

return hr;
}

// Helper function to register a CLSID as belonging to a component
// category
HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
{
// Register your component categories information.
ICatRegister* pcr = NULL ;
HRESULT hr = S_OK ;
hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICatRegister,
(void**)&pcr);
if (SUCCEEDED(hr))
{
// Register this category as being "implemented" by
// the class.
CATID rgcatid[1] ;
rgcatid[0] = catid;
hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
}

if (pcr != NULL)
pcr->Release();

return hr;
}



Modify the DllRegisterServer to mark the control as safe. Locate the implementation of DllRegisterServer in a .cpp file in yourproject. You will need to add several things to this .cpp file. Includethe file that implements CreateComponentCategory and RegisterCLSIDInCategory:

#include "CatHelp.h"
Define the GUID associated with the safety component categories:

const CATID CATID_SafeForScripting =
{0x7dd95801,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};
const CATID CATID_SafeForInitializing =
{0x7dd95802,0x9882,0x11cf,{0x9f,0xa9,0x00,0xaa,0x00,0x6c,0x42,0xc4}};
Define the GUID associated with your control. For simplicity, you can borrow the GUID from the IMPLEMENT_OLECREATE_EX macro in the main .cpp file for the control. Adjust the format slightly so that it looks like the following:

const GUID CDECL BASED_CODE _ctlid =
{ 0x43bd9e45, 0x328f, 0x11d0,
{ 0xa6, 0xb9, 0x0, 0xaa, 0x0, 0xa7, 0xf, 0xc2 } };
To mark your control as both Safe for Scripting and Initialization, modify the DllRegisterServer function as follows:

STDAPI DllRegisterServer(void)
{
AFX_MANAGE_STATE(_afxModuleAddrThis);

if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
return ResultFromScode(SELFREG_E_TYPELIB);

if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
return ResultFromScode(SELFREG_E_CLASS);

if (FAILED( CreateComponentCategory(
CATID_SafeForScripting,
L"Controls that are safely scriptable") ))
return ResultFromScode(SELFREG_E_CLASS);

if (FAILED( CreateComponentCategory(
CATID_SafeForInitializing,
L"Controls safely initializable from persistent data") ))
return ResultFromScode(SELFREG_E_CLASS);

if (FAILED( RegisterCLSIDInCategory(
_ctlid, CATID_SafeForScripting) ))
return ResultFromScode(SELFREG_E_CLASS);

if (FAILED( RegisterCLSIDInCategory(
_ctlid, CATID_SafeForInitializing) ))
return ResultFromScode(SELFREG_E_CLASS);

return NOERROR;
}



You would not normally modify the DllUnregisterServer function for these two reasons:


You would not want to remove a component category because other controls may be using it.


Although there is an UnRegisterCLSIDInCategory function defined, by default DllUnregisterServer removes the control's entry from the registry entirely. Therefore, removing the category from the control's registration is of little use.


After compiling and registering your control, you should find the following entries in the registry:

HKEY_CLASSES_ROOT\Component
Categories\{7DD95801-9882-11CF-9FA9-00AA006C42C4}

HKEY_CLASSES_ROOT\Component
Categories\{7DD95802-9882-11CF-9FA9-00AA006C42C4}

HKEY_CLASSES_ROOT\CLSID\{"your controls GUID"}\Implemented
Categories\{7DD95801-9882-11CF-9FA9-00AA006C42C4}

HKEY_CLASSES_ROOT\CLSID\{"your controls GUID"}\Implemented
Categories\{7DD95802-9882-11CF-9FA9-00AA006C42C4}



REFERENCES
Internet Client SDK - Component Development - Safe Initialization and Scripting for ActiveX Controls

Additional query words: safety scripting persistence initialization

Keywords : kbole kbfasttip kbActiveX kbCOMt kbCtrl kbInprocSvr kbInternet kbMFC kbVC420 kbVC500 kbVC600 kbGrpMFCATL
Version : WINDOWS:4.0,4.01; winnt:4.2,5.0,6.0
Platform : WINDOWS winnt
Issue type : kbhowto
Technology : kbvc


Last Reviewed: March 3, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
回复
richincsdn2 2001-09-01
email supperlxf@china.com
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……