// DllRegisterServer - Adds entries to the system registry STDAPI DllRegisterServer(void) { // registers object, typelib and all interfaces in typelib HRESULT hr; // return for safety functions AFX_MANAGE_STATE(AfxGetStaticModuleState()); if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid)) return ResultFromScode(SELFREG_E_TYPELIB); if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE)) return ResultFromScode(SELFREG_E_CLASS); // Mark the control as safe for initializing. hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data!"); if (FAILED(hr)) return hr; hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing); if (FAILED(hr)) return hr; // Mark the control as safe for scripting. hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!"); if (FAILED(hr)) return hr; hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting); if (FAILED(hr)) return hr; return NOERROR; }
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); //创建脚本安全“补充”项,非CLSID中 HRESULT hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!"); if (FAILED(hr)) return hr; //创建初始化安全“补充”项,非CLSID中 hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data!"); if (FAILED(hr)) return hr; //设置控件CLSID中补充项的脚本安全项,与“补充”项中的脚本安全项对应 hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting); if (FAILED(hr)) return hr; //设置控件CLSID中补充项的初始化安全项,与“补充”项中的初始化安全项对应 hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing); if (FAILED(hr)) return hr; return NOERROR; }
BOOL CJs2nCtrl::CJs2nCtrlFactory::UpdateRegistry(BOOL bRegister) { if (bRegister) { BOOL retval = AfxOleRegisterControlClass( AfxGetInstanceHandle(), m_clsid, m_lpszProgID, IDS_Js2n, IDB_Js2n, afxRegApartmentThreading, _dwJs2nOleMisc, _tlid, _wVerMajor, _wVerMinor); // mark as safe for scripting--failure OK HRESULT hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls that are safely scriptable"); if (SUCCEEDED(hr)) // only register if category exists RegisterCLSIDInCategory(m_clsid, CATID_SafeForScripting); // don't care if this call fails // mark as safe for data initialization hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data"); if (SUCCEEDED(hr)) // only register if category exists RegisterCLSIDInCategory(m_clsid, CATID_SafeForInitializing); // don't care if this call fails return retval; } else // since unregistering the class automatically eliminates // the category registration and since we don't want to // remove the categories, we don't need to do anything special return AfxOleUnregisterClass(m_clsid, m_lpszProgID); }
BOOL UpdateRegistry (BOOL fRegister) { // unseren aktuellen Namen besorgen { CCurrentUser regCfg (KEY_READ, g_cbRegConfig); DWORD dwSize = _MAX_PATH; if (!regCfg.GetSubSZ (g_cbTRiASName, g_cbTRiAS, dwSize)) strcpy (g_cbTRiAS, g_cbCopyrightName); // default } if (fRegister) { // RegDB initialisieren // Erweiterung selbst registrieren if (!ExtOleRegisterExtensionClass (_Module.GetModuleInstance(), CLSID_Statist, g_cbStatistProgID, IDS_LONGCLASSNAME, STATIST_MAJORVERSION, STATIST_MINORVERSION, EFPreLoad|EFUnLoadable)) return FALSE; // registers component categories CString strCatId; strCatId.Format(IDS_CATIDDESC_STATVALUE, g_cbTRiAS); _ASSERTE(strCatId.GetLength() > 0); CreateComponentCategory (CATID_TRiASStatistValue, strCatId); strCatId.Format (IDS_CATIDDESC_STATVALUESCONTAINER, g_cbTRiAS); _ASSERTE(strCatId.GetLength() > 0); CreateComponentCategory (CATID_TRiASStatistValuesContainer, strCatId); } else { // RegDB säubern RemoveComponentCategory (CATID_TRiASStatistValuesContainer); RemoveComponentCategory (CATID_TRiASStatistValue); if (!ExtOleUnregisterClass (CLSID_Statist, g_cbStatistProgID)) return FALSE; } return TRUE; // alles ok }
STDAPI DllRegisterServer(void) { HRESULT hr; AFX_MANAGE_STATE(_afxModuleAddrThis); if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid)) { return ResultFromScode(SELFREG_E_TYPELIB);//lint !e835 } if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE)) { return ResultFromScode(SELFREG_E_CLASS); } hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data!"); //lint !e1776 MFC自动生成的的函数 if (FAILED(hr)) { return hr; } hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing); if (FAILED(hr)) { return hr; } hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!"); //lint !e1776 MFC自动生成的的函数 if (FAILED(hr)) { return hr; } hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting); if (FAILED(hr)) { return hr; } return NOERROR; }//lint !e1788
STDAPI DllRegisterServer(void) { USES_CONVERSION; // registers object, typelib and all interfaces in typelib HRESULT hr = _Module.RegisterServer(TRUE); if (FAILED(hr)) return hr; // Mark the control as safe for initializing. hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data!"); if (FAILED(hr)) return hr; // MessageBox(NULL, "3", "", MB_OK); hr = RegisterCLSIDInCategory(CLSID_LHTMLActiveDocument, CATID_SafeForInitializing); if (FAILED(hr)) return hr; // MessageBox(NULL, "4", "", MB_OK); // Mark the control as safe for scripting. hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!"); if (FAILED(hr)) return hr; // MessageBox(NULL, "5", "", MB_OK); hr = RegisterCLSIDInCategory(CLSID_LHTMLActiveDocument, CATID_SafeForScripting); if (FAILED(hr)) return hr; { LPOLESTR clsidString; StringFromCLSID(CLSID_LHTMLActiveDocument, &clsidString); TCHAR filename[MAX_PATH]; { CRegKey key; key.Open(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE"); DWORD dwCount = sizeof(filename); key.QueryValue(filename, NULL, &dwCount); } // MessageBox(NULL, "7", "", MB_OK); { CRegKey key; key.Create(HKEY_CLASSES_ROOT, "svgfile\\CLSID"); key.SetValue(W2A(clsidString)); } { CRegKey key; key.Create(HKEY_CLASSES_ROOT, "svgfile\\DefaultIcon"); key.SetValue("%SystemRoot%\\system32\\url.dll,0"); } // MessageBox(NULL, "8", "", MB_OK); { CRegKey key; key.Create(HKEY_CLASSES_ROOT, "svgfile\\shell\\open\\command"); TCHAR value[512]; sprintf(value, "%s -nohome %%1", filename); key.SetValue(value); } // File extension associations { CRegKey key; key.Create(HKEY_CLASSES_ROOT, ".svg"); key.SetValue("svgfile"); key.SetValue("image/svg+xml", "Content Type"); } { CRegKey key; key.Create(HKEY_CLASSES_ROOT, ".svgz"); key.SetValue("svgfile"); key.SetValue("image/svg+xml", "Content Type"); } { CRegKey key; key.Create(HKEY_CLASSES_ROOT, ".xht"); key.SetValue("svgfile"); key.SetValue("application/xhtml+xml", "Content Type"); } // Mime associations { CRegKey key; key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\image/svg+xml"); key.SetValue(".svg", "Extension"); key.SetValue(W2A(clsidString), "CLSID"); } /* { CRegKey key; key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\image/svg+xml"); key.SetValue(".svgz", "Extension"); key.SetValue(W2A(clsidString), "CLSID"); } */ { CRegKey key; key.Create(HKEY_CLASSES_ROOT, "mime\\Database\\Content Type\\application/xhtml+xml"); key.SetValue(".xht", "Extension"); key.SetValue(W2A(clsidString), "CLSID"); } /////////// CoTaskMemFree(clsidString); SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); } return 0; }
// コマンドライン引数からCOMサーバー登録/削除を行う static int RegisterCOMServer(int &nRet, bool &bRun, bool &bAutomation, bool &bTray) { HRESULT hRes; TCHAR szTokens[] = _T("-/"); LPCTSTR lpszToken = _Module.FindOneOf(::GetCommandLine(), szTokens); while (lpszToken) { CString strToken = Misc::GetStrWord(lpszToken, &lpszToken); if (strToken.CompareNoCase(_T("UnregServer") ) == 0) { nRet = _Module.UnregisterServer(); nRet = UnRegisterCLSIDInCategory(CLSID_API, CATID_SafeForInitializing); if ( FAILED(nRet) ) return nRet; nRet = UnRegisterCLSIDInCategory(CLSID_API, CATID_SafeForScripting); if ( FAILED(nRet) ) return nRet; ::MessageBox(NULL, _T("COMサーバー削除しました。"), _T("unDonut"), 0); bRun = false; break; } else if (strToken.CompareNoCase(_T("RegServer") ) == 0) { nRet = _Module.RegisterServer(TRUE, &CLSID_API); if (nRet == S_OK) { // Mark the control as safe for initializing. hRes = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data"); if ( FAILED(hRes) ) return hRes; hRes = RegisterCLSIDInCategory(CLSID_API, CATID_SafeForInitializing); if ( FAILED(hRes) ) return hRes; // Mark the control as safe for scripting. hRes = CreateComponentCategory(CATID_SafeForScripting, L"Controls that are safely scriptable"); if ( FAILED(hRes) ) return hRes; hRes = RegisterCLSIDInCategory(CLSID_API, CATID_SafeForScripting); if ( FAILED(hRes) ) return hRes; ::MessageBox(NULL, _T("COMサーバー登録しました。"), _T("unDonut"), 0); } else ::MessageBox(NULL, _T("COMサーバー登録失敗しました。"), _T("unDonut"), 0); bRun = false; break; } else if (strToken.CompareNoCase(_T("Automation")) == 0 || (strToken.CompareNoCase(_T("Embedding" )) == 0) ) { bAutomation = true; break; #if 1 //+++ } else if (strToken.CompareNoCase(_T("tray") ) == 0) { bTray = true; break; #endif } lpszToken = _Module.FindOneOf(lpszToken, szTokens); } return S_OK; }