// Remove entries from the system registry STDAPI DllUnregisterServer(void) { LPWSTR pwszModule; // If we can't find the path to the DLL, we can't unregister... if ( ! FGetModuleFileName( v_hModule, &pwszModule) ) return E_UNEXPECTED; return _AtlModule.DllUnregisterServer(); }
STDAPI DllRegisterServer(void) { LPWSTR pwszModule; // If we can't find the path to the DLL, we can't register... if (!FGetModuleFileName( v_hModule, &pwszModule) ) return E_UNEXPECTED; // registers object, typelib and all interfaces in typelib HRESULT hr = _AtlModule.DllRegisterServer(); return hr; }
//////////////////////////////////////////////////////////////////////// // DllRegisterServer // // Registration of the OCX. // STDAPI DllRegisterServer() { HRESULT hr = S_OK; HKEY hk, hk2; DWORD dwret; CHAR szbuffer[256]; LPWSTR pwszModule; ITypeInfo* pti; // If we can't find the path to the DLL, we can't register... if (!FGetModuleFileName(v_hModule, &pwszModule)) return E_FAIL; // Setup the CLSID. This is the most important. If there is a critical failure, // we will set HR = GetLastError and return... if ((dwret = RegCreateKeyEx(HKEY_CLASSES_ROOT, "CLSID\\"DSOFRAMERCTL_CLSIDSTR, 0, NULL, 0, KEY_WRITE, NULL, &hk, NULL)) != ERROR_SUCCESS) { DsoMemFree(pwszModule); return HRESULT_FROM_WIN32(dwret); } lstrcpy(szbuffer, DSOFRAMERCTL_SHORTNAME); RegSetValueEx(hk, NULL, 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); // Setup the InprocServer32 key... dwret = RegCreateKeyEx(hk, "InprocServer32", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL); if (dwret == ERROR_SUCCESS) { lstrcpy(szbuffer, "Apartment"); RegSetValueEx(hk2, "ThreadingModel", 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); // We call a wrapper function for this setting since the path should be // stored in Unicode to handle non-ANSI file path names on some systems. // This wrapper will convert the path to ANSI if we are running on Win9x. // The rest of the Reg calls should be OK in ANSI since they do not // contain non-ANSI/Unicode-specific characters... if (!FSetRegKeyValue(hk2, pwszModule)) hr = E_ACCESSDENIED; RegCloseKey(hk2); dwret = RegCreateKeyEx(hk, "ProgID", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL); if (dwret == ERROR_SUCCESS) { lstrcpy(szbuffer, DSOFRAMERCTL_PROGID); RegSetValueEx(hk2, NULL, 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); RegCloseKey(hk2); } } else hr = HRESULT_FROM_WIN32(dwret); if (SUCCEEDED(hr)) { dwret = RegCreateKeyEx(hk, "Control", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL); if (dwret == ERROR_SUCCESS) { RegCloseKey(hk2); } else hr = HRESULT_FROM_WIN32(dwret); } // If we succeeded so far, andle the remaining (non-critical) reg keys... if (SUCCEEDED(hr)) { dwret = RegCreateKeyEx(hk, "ToolboxBitmap32", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL); if (dwret == ERROR_SUCCESS) { LPWSTR pwszT = DsoCopyStringCat(pwszModule, L",102"); if (pwszT) { FSetRegKeyValue(hk2, pwszT); DsoMemFree(pwszT); } RegCloseKey(hk2); } dwret = RegCreateKeyEx(hk, "TypeLib", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL); if (dwret == ERROR_SUCCESS) { lstrcpy(szbuffer, DSOFRAMERCTL_TLIBSTR); RegSetValueEx(hk2, NULL, 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); RegCloseKey(hk2); } dwret = RegCreateKeyEx(hk, "Version", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL); if (dwret == ERROR_SUCCESS) { lstrcpy(szbuffer, DSOFRAMERCTL_VERSIONSTR); RegSetValueEx(hk2, NULL, 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); RegCloseKey(hk2); } dwret = RegCreateKeyEx(hk, "MiscStatus", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL); if (dwret == ERROR_SUCCESS) { lstrcpy(szbuffer, "131473"); RegSetValueEx(hk2, NULL, 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); RegCloseKey(hk2); } dwret = RegCreateKeyEx(hk, "DataFormats\\GetSet\\0", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL); if (dwret == ERROR_SUCCESS) { lstrcpy(szbuffer, "3,1,32,1"); RegSetValueEx(hk2, NULL, 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); RegCloseKey(hk2); } } RegCloseKey(hk); DsoMemFree(pwszModule); // This should catch any critical failures during setup of CLSID... RETURN_ON_FAILURE(hr); // Setup the ProgID (non-critical)... if (RegCreateKeyEx(HKEY_CLASSES_ROOT, DSOFRAMERCTL_PROGID, 0, NULL, 0, KEY_WRITE, NULL, &hk, NULL) == ERROR_SUCCESS) { lstrcpy(szbuffer, DSOFRAMERCTL_FULLNAME); RegSetValueEx(hk, NULL, 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); if (RegCreateKeyEx(hk, "CLSID", 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL) == ERROR_SUCCESS) { lstrcpy(szbuffer, DSOFRAMERCTL_CLSIDSTR); RegSetValueEx(hk2, NULL, 0, REG_SZ, (BYTE *)szbuffer, lstrlen(szbuffer)); RegCloseKey(hk2); } RegCloseKey(hk); } // Load the type info (this should register the lib once)... hr = DsoGetTypeInfoEx(LIBID_DSOFramer, 0, DSOFRAMERCTL_VERSION_MAJOR, DSOFRAMERCTL_VERSION_MINOR, v_hModule, CLSID_FramerControl, &pti); if (SUCCEEDED(hr)) pti->Release(); return hr; }