void RegisterInterface(HMODULE hModule, // DLL module handle const CLSID& clsid, // Class ID const char* szFriendlyName, // Friendly Name const CLSID &libid, const IID &iid) { // Get server location. char szModule[512] ; DWORD dwResult = ::GetModuleFileNameA(hModule, szModule, sizeof(szModule)/sizeof(char)) ; assert(dwResult != 0) ; // Convert the CLSID into a char. char szCLSID[CLSID_STRING_SIZE] ; CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)) ; char szLIBID[CLSID_STRING_SIZE] ; CLSIDtochar(libid, szLIBID, sizeof(szCLSID)) ; char szIID[CLSID_STRING_SIZE] ; CLSIDtochar(iid, szIID, sizeof(szCLSID)) ; // Build the key Interface\\{...} char szKey[64] ; strcpy(szKey, "Interface\\") ; strcat(szKey, szIID) ; // Add the value to the registry. setKeyAndValue(szKey, NULL, szFriendlyName) ; char szKey2[MAX_PATH]; strcpy(szKey2, szKey); strcat(szKey2, "\\ProxyStubClsID"); // Add the server filename subkey under the IID key. setKeyAndValue(szKey2, NULL, "{00020424-0000-0000-C000-000000000046}"); //IUnknown strcpy(szKey2, szKey); strcat(szKey2, "\\ProxyStubClsID32"); // Add the server filename subkey under the IID key. setKeyAndValue(szKey2, NULL, "{00020424-0000-0000-C000-000000000046}"); //IUnknown strcpy(szKey2, szKey); strcat(szKey2, "\\TypeLib"); // Add the server filename subkey under the CLSID key. setKeyAndValue(szKey2, NULL, szLIBID) ; setValue(szKey2, "Version", "1.0") ; }
// Remove the component from the registry. LONG UnregisterServer(REFCLSID clsid, // Class ID const char* szVerIndProgID, // Programmatic const char* szProgID) // IDs { // Convert the CLSID into a char. char szCLSID[CLSID_STRING_SIZE]; CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)); // Build the key CLSID\\{...} char szKey[64]; strcpy(szKey, "CLSID\\"); strcat(szKey, szCLSID); // Delete the CLSID Key - CLSID\{...} LONG lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szKey); assert((lResult == ERROR_SUCCESS) || (lResult == ERROR_FILE_NOT_FOUND)); // Subkey may not exist. // Delete the version-independent ProgID Key. lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szVerIndProgID); assert((lResult == ERROR_SUCCESS) || (lResult == ERROR_FILE_NOT_FOUND)); // Subkey may not exist. // Delete the ProgID key. lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szProgID); assert((lResult == ERROR_SUCCESS) || (lResult == ERROR_FILE_NOT_FOUND)); // Subkey may not exist. return S_OK; }
// Register the component in the registry. HRESULT RegisterServer(const char* szModuleName, // DLL module handle REFCLSID clsid, // Class ID const char* szFriendlyName, // Friendly Name const char* szVerIndProgID, // Programmatic const char* szProgID, // IDs const char* szThreadingModel) // ThreadingModel { // Get server location. char szModule[512]; HMODULE hModule = GetModuleHandle(szModuleName); DWORD dwResult = GetModuleFileName(hModule, szModule, sizeof(szModule)/sizeof(char)); assert(dwResult != 0); // Convert the CLSID into a char. char szCLSID[CLSID_STRING_SIZE]; CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)); // Build the key CLSID\\{...} char szKey[64]; strcpy(szKey, "CLSID\\"); strcat(szKey, szCLSID); // Add the CLSID to the registry. setKeyAndValue(szKey, NULL, szFriendlyName); // Add the server filename subkey under the CLSID key. if(strstr(szModuleName, ".exe") == NULL) { setKeyAndValue(szKey, "InprocServer32", szModule); char szInproc[64]; strcpy(szInproc, szKey); strcat(szInproc, "\\InprocServer32"); setValueInKey(szInproc, "ThreadingModel", szThreadingModel); } else setKeyAndValue(szKey, "LocalServer32", szModule); // Add the ProgID subkey under the CLSID key. setKeyAndValue(szKey, "ProgID", szProgID); // Add the version-independent ProgID subkey under CLSID key. setKeyAndValue(szKey, "VersionIndependentProgID", szVerIndProgID); // Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT. setKeyAndValue(szVerIndProgID, NULL, szFriendlyName); setKeyAndValue(szVerIndProgID, "CLSID", szCLSID); setKeyAndValue(szVerIndProgID, "CurVer", szProgID); // Add the versioned ProgID subkey under HKEY_CLASSES_ROOT. setKeyAndValue(szProgID, NULL, szFriendlyName); setKeyAndValue(szProgID, "CLSID", szCLSID); return S_OK; }
void UnregisterInterface(const IID &iid) { char szIID[CLSID_STRING_SIZE] ; CLSIDtochar(iid, szIID, sizeof(szIID)) ; // Build the key Interface\\{...} char szKey[64] ; strcpy(szKey, "Interface\\") ; strcat(szKey, szIID) ; LONG lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szKey) ; }
// // Register the component in the registry. // HRESULT RegisterServer(HMODULE hModule, // DLL module handle const CLSID& clsid, // Class ID const char* szFriendlyName, // Friendly Name const char* szVerIndProgID, // Programmatic const char* szProgID) // IDs { // Get server location. char szModule[512] ; DWORD dwResult = ::GetModuleFileName(hModule, szModule, sizeof(szModule)/sizeof(char)) ; assert(dwResult != 0) ; // Convert the CLSID into a char. char szCLSID[CLSID_STRING_SIZE] ; CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)) ; // Build the key CLSID\\{...} char szKey[64] ; strcpy(szKey, "CLSID\\") ; strcat(szKey, szCLSID) ; // Add the CLSID to the registry. setKeyAndValue(szKey, NULL, szFriendlyName) ; // Add the server filename subkey under the CLSID key. setKeyAndValue(szKey, "InprocServer32", szModule) ; // Add the ProgID subkey under the CLSID key. setKeyAndValue(szKey, "ProgID", szProgID) ; // Add the version-independent ProgID subkey under CLSID key. setKeyAndValue(szKey, "VersionIndependentProgID", szVerIndProgID) ; // Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT. setKeyAndValue(szVerIndProgID, NULL, szFriendlyName) ; setKeyAndValue(szVerIndProgID, "CLSID", szCLSID) ; setKeyAndValue(szVerIndProgID, "CurVer", szProgID) ; // Add the versioned ProgID subkey under HKEY_CLASSES_ROOT. setKeyAndValue(szProgID, NULL, szFriendlyName) ; setKeyAndValue(szProgID, "CLSID", szCLSID) ; return S_OK ; }
LONG UnregisterServer(const CLSID& clsid, // Class ID const char* szVerIndProgID, // Programmatic const char* szProgID) // IDs { LONG lResult = S_OK; // Convert the CLSID into a char. char szCLSID[CLSID_STRING_SIZE]; if (!CLSIDtochar(clsid, szCLSID, sizeof(szCLSID))) return S_FALSE; UnRegisterProxy(); nsCAutoString registryKey("CLSID\\"); registryKey += szCLSID; lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, registryKey.get()); if (lResult == ERROR_SUCCESS || lResult == ERROR_FILE_NOT_FOUND) return lResult; registryKey += "\\LocalServer32"; // Delete only the path for this server. lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, registryKey.get()); if (lResult != ERROR_SUCCESS && lResult != ERROR_FILE_NOT_FOUND) return lResult; // Delete the version-independent ProgID Key. lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szVerIndProgID); if (lResult != ERROR_SUCCESS && lResult != ERROR_FILE_NOT_FOUND) return lResult; lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szProgID); return lResult; }
// // Register the component in the registry. // HRESULT RegisterServer(HMODULE hModule, // DLL module handle const CLSID& clsid, // Class ID const char* szFriendlyName, // Friendly Name const char* szVerIndProgID, // Programmatic const char* szProgID, const CLSID &libid) // Type lib ID { // Get server location. char szModule[1024]; DWORD dwResult = ::GetModuleFileNameA(hModule, szModule, sizeof(szModule)/sizeof(char)) ; assert(dwResult != 0) ; // Convert the CLSID into a char. char szCLSID[CLSID_STRING_SIZE] ; CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)) ; char szLIBID[CLSID_STRING_SIZE] ; CLSIDtochar(libid, szLIBID, sizeof(szLIBID)) ; // Build the key CLSID\\{...} char szKey[64] ; strcpy(szKey, "CLSID\\") ; strcat(szKey, szCLSID) ; // Add the CLSID to the registry. setKeyAndValue(szKey, NULL, szFriendlyName) ; // Add the server filename subkey under the CLSID key. char szModuleExeOrDll[4]; long nLength = (long)strlen(szModule); strncpy(szModuleExeOrDll, szModule+nLength-3, 3); szModuleExeOrDll[3] = 0; if (_stricmp(szModuleExeOrDll,"exe")==0) setKeyAndValue(szKey, "LocalServer32", szModule) ; else { setKeyAndValue(szKey, "InProcServer32", szModule) ; char szKeyInProc[64]; strcpy(szKeyInProc, szKey); strcat(szKeyInProc, "\\InProcServer32"); setValue(szKeyInProc, "ThreadingModel", "Both") ; } // Add the ProgID subkey under the CLSID key. setKeyAndValue(szKey, "ProgID", szProgID) ; // Add the version-independent ProgID subkey under CLSID key. setKeyAndValue(szKey, "VersionIndependentProgID", szVerIndProgID) ; // Add the typelib setKeyAndValue(szKey, "TypeLib", szLIBID) ; // Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT. setKeyAndValue(szVerIndProgID, NULL, szFriendlyName) ; setKeyAndValue(szVerIndProgID, "CLSID", szCLSID) ; setKeyAndValue(szVerIndProgID, "CurVer", szProgID) ; // Add the versioned ProgID subkey under HKEY_CLASSES_ROOT. setKeyAndValue(szProgID, NULL, szFriendlyName) ; setKeyAndValue(szProgID, "CLSID", szCLSID) ; // add TypeLib keys strcpy(szKey, "TypeLib\\") ; strcat(szKey, szLIBID) ; // Add the CLSID to the registry. setKeyAndValue(szKey, NULL, NULL) ; strcat(szKey, "\\1.0"); setKeyAndValue(szKey, NULL, szFriendlyName) ; strcat(szKey, "\\0"); setKeyAndValue(szKey, NULL, NULL) ; strcat(szKey, "\\win32"); setKeyAndValue(szKey, NULL, szModule) ; return S_OK ; }
HRESULT RegisterServer(const CLSID& clsid, // Class ID const char* szFriendlyName, // Friendly Name const char* szVerIndProgID, // Programmatic const char* szProgID) // IDs { HMODULE hModule = GetModuleHandle(NULL); char szModuleName[MAX_SIZE]; char szCLSID[CLSID_STRING_SIZE]; nsCAutoString independentProgId(szVerIndProgID); nsCAutoString progId(szProgID); DWORD dwResult = ::GetModuleFileName(hModule, szModuleName, sizeof(szModuleName)/sizeof(char)); if (dwResult == 0) return S_FALSE; nsCAutoString moduleName(szModuleName); nsCAutoString registryKey("CLSID\\"); moduleName += MAPI_STARTUP_ARG; // Convert the CLSID into a char. if (!CLSIDtochar(clsid, szCLSID, sizeof(szCLSID))) return S_FALSE; registryKey += szCLSID; // Add the CLSID to the registry. if (!setKeyAndValue(registryKey, NULL, szFriendlyName)) return S_FALSE; if (!setKeyAndValue(registryKey, "LocalServer32", moduleName.get())) return S_FALSE; // Add the ProgID subkey under the CLSID key. if (!setKeyAndValue(registryKey, "ProgID", szProgID)) return S_FALSE; // Add the version-independent ProgID subkey under CLSID key. if (!setKeyAndValue(registryKey, "VersionIndependentProgID", szVerIndProgID)) return S_FALSE; // Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT. if (!setKeyAndValue(independentProgId, NULL, szFriendlyName)) return S_FALSE; if (!setKeyAndValue(independentProgId, "CLSID", szCLSID)) return S_FALSE; if (!setKeyAndValue(independentProgId, "CurVer", szProgID)) return S_FALSE; // Add the versioned ProgID subkey under HKEY_CLASSES_ROOT. if (!setKeyAndValue(progId, NULL, szFriendlyName)) return S_FALSE; if (!setKeyAndValue(progId, "CLSID", szCLSID)) return S_FALSE; RegisterProxy(); return S_OK; }