• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            小步慢跑

             

            標記ocx控件為腳本安全

            MFC開發的OCX控件即使使用了簽名。在IE中運行是也會提示“頁面中的OCX的交互是不安全的。。。。”。解決辦法有兩種

            方案1:修改IE的設置:

            image

            方案2:標記控件為腳本安全的

            在工程中增加頭文件 cathelp.h

            #ifndef _CATHELP_H_
            
            #define _CATHELP_H_
            
            #include <comcat.h>
            
            HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription);
            
            HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
            
            HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
            
            #endif

            增加cathelp.cpp

            #include "cathelp.h"
            
            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';
            
            	
            
            	if(pcr)
            
            	{
            
            		hr = pcr->RegisterCategories(1, &catinfo);
            
            		pcr->Release();
            
            	}
            
            	
            
            	return hr;
            
            }
            
            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;
            
            }
            
            HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
            
            {
            
                ICatRegister* pcr = NULL ;
            
                HRESULT hr = S_OK ;
            
                hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
            
            		NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
            
                if (SUCCEEDED(hr))
            
                {
            
            		// Unregister this category as being "implemented" by
            
            		// the class.
            
            		CATID rgcatid[1] ;
            
            		rgcatid[0] = catid;
            
            		hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
            
                }
            
            	
            
                if (pcr != NULL)
            
                    pcr->Release();
            
            	
            
            	return hr;
            
            }

             

            修改 ocx的 DllRegisterServer 方法

            #include "cathelp.h"
            
            #include <objsafe.h>//for CATID_SafeForInitializing
            
            #include "SafeocxtestCtl.h"
            
            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(
            
            		CSafeocxtestCtrl::guid, CATID_SafeForScripting) ))
            
            		return ResultFromScode(SELFREG_E_CLASS);
            
            	
            
            	if (FAILED( RegisterCLSIDInCategory(
            
            		CSafeocxtestCtrl::guid, CATID_SafeForInitializing) ))
            
                            return ResultFromScode(SELFREG_E_CLASS);
            
                
            
            	return NOERROR;
            
            }
            
            /////////////////////////////////////////////////////////////////////////////
            
            // DllUnregisterServer - Removes entries from the system registry
            
            STDAPI DllUnregisterServer(void)
            
            {
            
            	AFX_MANAGE_STATE(_afxModuleAddrThis);
            
            	if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
            
            		return ResultFromScode(SELFREG_E_TYPELIB);
            
            	if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
            
            		return ResultFromScode(SELFREG_E_CLASS);
            
            	// 控件安全反初始化
            
                UnRegisterCLSIDInCategory(	CSafeocxtestCtrl::guid, CATID_SafeForScripting);
            
                UnRegisterCLSIDInCategory(	CSafeocxtestCtrl::guid, CATID_SafeForInitializing);
            
                
            
               
            
            	return NOERROR;
            
            }
            

            編譯注冊就OK了。

             

            如果要查看ocx是否是腳本安全的。在注冊表HKEY_CLASSES_ROOT\CLSID\OCX的clsid\Implemented Categories\ 下看一下有沒有“{7DD95801-9882-11CF-9FA9-00AA006C42C4}” 和“{7DD95802-9882-11CF-9FA9-00AA006C42C4}”

            下圖就是腳本安全的:

            image

             

            參考:http://support.microsoft.com/kb/161873/en-us

            posted on 2013-04-24 10:30 zaccheo 閱讀(609) 評論(0)  編輯 收藏 引用 所屬分類: win32/MFC

            導航

            統計

            常用鏈接

            留言簿

            隨筆分類(23)

            隨筆檔案(26)

            文章分類(1)

            文章檔案(1)

            csdn

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久婷婷午色综合夜啪| 午夜福利91久久福利| 亚洲AV日韩AV永久无码久久| 人妻无码αv中文字幕久久| 久久Av无码精品人妻系列| 国产精品视频久久| 久久AⅤ人妻少妇嫩草影院| 色综合久久精品中文字幕首页| 久久国产成人精品国产成人亚洲| 少妇被又大又粗又爽毛片久久黑人| 日韩精品无码久久久久久| 久久精品国产一区| 蜜臀久久99精品久久久久久| 日日噜噜夜夜狠狠久久丁香五月 | 久久天天躁狠狠躁夜夜96流白浆| 久久强奷乱码老熟女网站| 97久久精品无码一区二区天美| 欧美精品丝袜久久久中文字幕 | 欧美伊人久久大香线蕉综合69| 国内精品久久久久影院薰衣草| 久久国产精品久久国产精品| 亚洲综合日韩久久成人AV| 久久五月精品中文字幕| 狠狠色丁香久久综合婷婷| 亚洲αv久久久噜噜噜噜噜| 无码人妻少妇久久中文字幕| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久av免费天堂小草播放| 亚洲人成电影网站久久| 久久精品一区二区| 久久综合久久鬼色| 激情综合色综合久久综合| 青青青青久久精品国产| 久久精品国产亚洲AV香蕉| 久久久久久久久无码精品亚洲日韩| 欧美成人免费观看久久| 三级三级久久三级久久| 久久人人爽人人爽人人片av麻烦 | 久久久久亚洲AV综合波多野结衣| 久久久国产精品福利免费| 国产午夜久久影院|