// 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 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") ; }
static void registerFactory( const CLSID& clsid, const char* pcszFriendlyName ) { // Get server location. char szModule[ _MAX_PATH ]; ::GetModuleFileName( theApp.m_hInstance, szModule, sizeof szModule ); // Convert the CLSID into a char. char szCLSID[ 128 ]; CLSIDToString( clsid, szCLSID, sizeof szCLSID ); // Add the CLSID to HKEY_CLASSES_ROOT\CLSID char szKey[ 64 ]; strlcpy( szKey, "CLSID\\", sizeof(szKey) ); strlcat( szKey, szCLSID, sizeof(szKey) ); setKeyAndValue( HKEY_CLASSES_ROOT, szKey, NULL, NULL, pcszFriendlyName ); // Add the pathname subkey under the CLSID key. setKeyAndValue( HKEY_CLASSES_ROOT, szKey, "InprocServer32", NULL, szModule ); }
// // 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 ; }
STDAPI DllRegisterServer() { registerFactory( CLSID_MackieControlXT, s_szMackieControlXTFriendlyName ); registerFactory( CLSID_MackieControlXTPropPage, s_szMackieControlXTFriendlyNamePropPage ); registerFactory( CLSID_MackieControlMaster, s_szMackieControlMasterFriendlyName ); registerFactory( CLSID_MackieControlMasterPropPage, s_szMackieControlMasterFriendlyNamePropPage ); registerFactory( CLSID_MackieControlC4, s_szMackieControlC4FriendlyName ); registerFactory( CLSID_MackieControlC4PropPage, s_szMackieControlC4FriendlyNamePropPage ); // Add the CLSID to HKEY_CLASSES_ROOT\CakewalkControlSurfaces char szCLSID[ 128 ]; char szKey[ 256 ]; CLSIDToString( CLSID_MackieControlXT, szCLSID, sizeof szCLSID ); strlcpy( szKey, "CakewalkControlSurfaces\\", sizeof(szKey) ); strlcat( szKey, szCLSID, sizeof(szKey) ); setKeyAndValue( HKEY_CLASSES_ROOT, szKey, NULL, "Description", s_szMackieControlXTFriendlyName ); setKeyAndValue( HKEY_CLASSES_ROOT, szKey, NULL, "HelpFilePath", "" ); CLSIDToString( CLSID_MackieControlMaster, szCLSID, sizeof szCLSID ); strlcpy( szKey, "CakewalkControlSurfaces\\", sizeof(szKey) ); strlcat( szKey, szCLSID, sizeof(szKey) ); setKeyAndValue( HKEY_CLASSES_ROOT, szKey, NULL, "Description", s_szMackieControlMasterFriendlyName ); setKeyAndValue( HKEY_CLASSES_ROOT, szKey, NULL, "HelpFilePath", "" ); CLSIDToString( CLSID_MackieControlC4, szCLSID, sizeof szCLSID ); strlcpy( szKey, "CakewalkControlSurfaces\\", sizeof(szKey) ); strlcat( szKey, szCLSID, sizeof(szKey) ); setKeyAndValue( HKEY_CLASSES_ROOT, szKey, NULL, "Description", s_szMackieControlC4FriendlyName ); setKeyAndValue( HKEY_CLASSES_ROOT, szKey, NULL, "HelpFilePath", "" ); return S_OK; }
// // Register the component in the registry. // HRESULT RegisterServer(HMODULE hModule, // DLL module handle const CLSID& clsid, // Class ID LPCTSTR szFriendlyName, // Friendly Name LPCTSTR szVerIndProgID, // Programmatic LPCTSTR szProgID, // IDs const GUID& libid) { // Get server location. TCHAR szModule[512]; DWORD dwResult = ::GetModuleFileName(hModule, szModule, sizeof(szModule) / sizeof (TCHAR)); assert(dwResult != 0); // Convert the CLSID into a TCHAR. TCHAR szCLSID[GUID_STRING_SIZE]; GUIDtoChar(clsid, szCLSID, sizeof(szCLSID)); // Build the key CLSID\\{...} TCHAR szKey[64]; #ifndef _UNICODE strcpy(szKey, _T("CLSID\\")); strcat(szKey, szCLSID); #else wcscpy(szKey, _T("CLSID\\")); wcscat(szKey, szCLSID); #endif // _UNICODE // Add the CLSID to the registry. setKeyAndValue(szKey, NULL, szFriendlyName); // Add the server filename subkey under the CLSID key. #ifdef _OUTPROC_SERVER_ setKeyAndValue(szKey, _T("LocalServer32"), szModule); #else setKeyAndValue(szKey, _T("InprocServer32"), szModule); #endif // Add the ProgID subkey under the CLSID key. setKeyAndValue(szKey, _T("ProgID"), szProgID); // Add the version-independent ProgID subkey under CLSID key. setKeyAndValue(szKey, _T("VersionIndependentProgID"), szVerIndProgID); // Add the Type Library ID subkey under the CLSID key. #ifdef __AUTOMATION TCHAR szLIBID[GUID_STRING_SIZE] ; GUIDtoChar(libid, szLIBID, sizeof(szLIBID)) ; setKeyAndValue(szKey, _T("TypeLib"), szLIBID) ; #endif // __AUTOMATION // Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT. setKeyAndValue(szVerIndProgID, NULL, szFriendlyName); setKeyAndValue(szVerIndProgID, _T("CLSID"), szCLSID); setKeyAndValue(szVerIndProgID, _T("CurVer"), szProgID); // Add the versioned ProgID subkey under HKEY_CLASSES_ROOT. setKeyAndValue(szProgID, NULL, szFriendlyName); setKeyAndValue(szProgID, _T("CLSID"), szCLSID); return S_OK; }
// // 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; }