Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
7.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2001.
  5. //
  6. // File: regutil.cxx
  7. //
  8. // Contents: Functions supporting class registration
  9. //
  10. // History: 25 Oct 1996 Alanw Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. #include "regutil.h"
  16. #define GUID_SIZE 128
  17. //+---------------------------------------------------------------------------
  18. //
  19. // Function: _DllRegisterServer - public
  20. //
  21. // Synopsis: Installs a class registration for an inproc server
  22. //
  23. // Arguments: [hInst] -- HINSTANCE of DLL to be installed
  24. // [pwszProgId] -- program ID (class name)
  25. // [clsid] -- Class ID of class
  26. // [pwszDescription] -- description of class
  27. // [pwszCurVer] -- if non-NULL, current version
  28. //
  29. // Returns: SCODE - status of registration
  30. //
  31. // History: 03 Jan 1997 Alanw Added header
  32. //
  33. // NTRAID#DB-NTBUG9-84747-2000/07/31-dlee No transaction / Rollback semantics for DLL registration of IXSSO
  34. //
  35. //----------------------------------------------------------------------------
  36. STDAPI _DllRegisterServer(HINSTANCE hInst,
  37. LPWSTR pwszProgId,
  38. REFCLSID clsid,
  39. LPWSTR pwszDescription,
  40. LPWSTR pwszCurVer)
  41. {
  42. HKEY hKey;
  43. WCHAR wcsSubKey[MAX_PATH+1];
  44. WCHAR wcsClsId[GUID_SIZE+1];
  45. StringFromGUID2(clsid, wcsClsId, sizeof(wcsClsId) / sizeof WCHAR);
  46. LONG r = RegCreateKey(HKEY_CLASSES_ROOT, pwszProgId, &hKey);
  47. if ( ERROR_SUCCESS != r )
  48. return HRESULT_FROM_WIN32( r );
  49. r = RegSetValue(hKey, NULL, REG_SZ,
  50. pwszDescription, wcslen(pwszDescription) * sizeof (WCHAR));
  51. RegCloseKey(hKey);
  52. if ( ERROR_SUCCESS != r )
  53. return HRESULT_FROM_WIN32( r );
  54. wsprintf(wcsSubKey, L"%ws\\CLSID", pwszProgId);
  55. r = RegCreateKey(HKEY_CLASSES_ROOT, wcsSubKey, &hKey);
  56. if ( ERROR_SUCCESS != r )
  57. return HRESULT_FROM_WIN32( r );
  58. r = RegSetValue(hKey, NULL, REG_SZ,
  59. wcsClsId, wcslen(wcsClsId) * sizeof (WCHAR));
  60. RegCloseKey(hKey);
  61. if ( ERROR_SUCCESS != r )
  62. return HRESULT_FROM_WIN32( r );
  63. if ( pwszCurVer )
  64. {
  65. wsprintf(wcsSubKey, L"%ws\\CurVer", pwszProgId);
  66. r = RegCreateKey(HKEY_CLASSES_ROOT, wcsSubKey, &hKey);
  67. if ( ERROR_SUCCESS != r )
  68. return HRESULT_FROM_WIN32( r );
  69. r = RegSetValue(hKey, NULL, REG_SZ,
  70. pwszCurVer, wcslen(pwszCurVer) * sizeof (WCHAR));
  71. RegCloseKey(hKey);
  72. if ( ERROR_SUCCESS != r )
  73. return HRESULT_FROM_WIN32( r );
  74. }
  75. wsprintf(wcsSubKey, L"CLSID\\%ws", wcsClsId);
  76. r = RegCreateKey(HKEY_CLASSES_ROOT, wcsSubKey, &hKey);
  77. if ( ERROR_SUCCESS != r )
  78. return HRESULT_FROM_WIN32( r );
  79. r = RegSetValue(hKey, NULL, REG_SZ,
  80. pwszDescription, wcslen(pwszDescription) * sizeof (WCHAR));
  81. RegCloseKey(hKey);
  82. if ( ERROR_SUCCESS != r )
  83. return HRESULT_FROM_WIN32( r );
  84. wsprintf(wcsSubKey, L"CLSID\\%ws\\InProcServer32", wcsClsId);
  85. r = RegCreateKey(HKEY_CLASSES_ROOT, wcsSubKey, &hKey);
  86. if ( ERROR_SUCCESS != r )
  87. return HRESULT_FROM_WIN32( r );
  88. GetModuleFileName(hInst, wcsSubKey, MAX_PATH);
  89. r = RegSetValue(hKey, NULL, REG_SZ,
  90. wcsSubKey, wcslen(wcsSubKey) * sizeof (WCHAR));
  91. if ( ERROR_SUCCESS != r )
  92. return HRESULT_FROM_WIN32( r );
  93. wcscpy(wcsSubKey, L"Both");
  94. r = RegSetValueEx(hKey, L"ThreadingModel", NULL, REG_SZ,
  95. (BYTE*)wcsSubKey, wcslen(wcsSubKey) * sizeof (WCHAR));
  96. RegCloseKey(hKey);
  97. if ( ERROR_SUCCESS != r )
  98. return HRESULT_FROM_WIN32( r );
  99. wsprintf(wcsSubKey, L"CLSID\\%ws\\ProgID", wcsClsId);
  100. r = RegCreateKey(HKEY_CLASSES_ROOT, wcsSubKey, &hKey);
  101. if ( ERROR_SUCCESS != r )
  102. return HRESULT_FROM_WIN32( r );
  103. r = RegSetValue(hKey, NULL, REG_SZ,
  104. pwszProgId, wcslen(pwszProgId) * sizeof (WCHAR));
  105. RegCloseKey(hKey);
  106. if ( ERROR_SUCCESS != r )
  107. return HRESULT_FROM_WIN32( r );
  108. //
  109. // Indicate the object is 'safely' initializable and scriptable
  110. //
  111. wsprintf(wcsSubKey, L"CLSID\\%ws\\Implemented Categories", wcsClsId);
  112. r = RegCreateKey(HKEY_CLASSES_ROOT, wcsSubKey, &hKey);
  113. if ( ERROR_SUCCESS != r )
  114. return HRESULT_FROM_WIN32( r );
  115. RegCloseKey(hKey);
  116. wsprintf(wcsSubKey, L"CLSID\\%ws\\Implemented Categories\\{7DD95801-9882-11CF-9FA9-00AA006C42C4}", wcsClsId);
  117. r = RegCreateKey(HKEY_CLASSES_ROOT, wcsSubKey, &hKey);
  118. if ( ERROR_SUCCESS != r )
  119. return HRESULT_FROM_WIN32( r );
  120. RegCloseKey(hKey);
  121. wsprintf(wcsSubKey, L"CLSID\\%ws\\Implemented Categories\\{7DD95802-9882-11CF-9FA9-00AA006C42C4}", wcsClsId);
  122. r = RegCreateKey(HKEY_CLASSES_ROOT, wcsSubKey, &hKey);
  123. if ( ERROR_SUCCESS != r )
  124. return HRESULT_FROM_WIN32( r );
  125. RegCloseKey(hKey);
  126. return S_OK;
  127. }
  128. //+---------------------------------------------------------------------------
  129. //
  130. // Function: _DllUnregisterServer - public
  131. //
  132. // Synopsis: Uninstalls a class registration for an inproc server
  133. //
  134. // Arguments: [pwszProgId] -- program ID (class name)
  135. // [clsid] -- Class ID of class
  136. //
  137. // Returns: SCODE - status of de-registration
  138. //
  139. // History: 03 Jan 1997 Alanw Added header
  140. //
  141. //----------------------------------------------------------------------------
  142. STDAPI _DllUnregisterServer(LPWSTR pwszProgID, REFCLSID clsid)
  143. {
  144. //
  145. // Ignore errors -- do a best effort to uninstall since we don't know
  146. // what shape the registry is in.
  147. //
  148. WCHAR wcsClsId[GUID_SIZE+1];
  149. StringFromGUID2(clsid, wcsClsId, sizeof(wcsClsId) / sizeof WCHAR);
  150. WCHAR wcsSubKey[256];
  151. wsprintf(wcsSubKey, L"%ws\\CLSID", pwszProgID);
  152. RegDeleteKey(HKEY_CLASSES_ROOT, wcsSubKey);
  153. wsprintf(wcsSubKey, L"%ws\\CurVer", pwszProgID);
  154. RegDeleteKey(HKEY_CLASSES_ROOT, wcsSubKey);
  155. RegDeleteKey(HKEY_CLASSES_ROOT, pwszProgID);
  156. wsprintf(wcsSubKey, L"CLSID\\%ws\\InProcServer32", wcsClsId);
  157. RegDeleteKey(HKEY_CLASSES_ROOT, wcsSubKey);
  158. wsprintf(wcsSubKey, L"CLSID\\%ws\\ProgID", wcsClsId);
  159. RegDeleteKey(HKEY_CLASSES_ROOT, wcsSubKey);
  160. wsprintf(wcsSubKey, L"CLSID\\%ws\\Implemented Categories\\{7DD95801-9882-11CF-9FA9-00AA006C42C4}", wcsClsId);
  161. RegDeleteKey(HKEY_CLASSES_ROOT, wcsSubKey);
  162. wsprintf(wcsSubKey, L"CLSID\\%ws\\Implemented Categories\\{7DD95802-9882-11CF-9FA9-00AA006C42C4}", wcsClsId);
  163. RegDeleteKey(HKEY_CLASSES_ROOT, wcsSubKey);
  164. wsprintf(wcsSubKey, L"CLSID\\%ws\\Implemented Categories", wcsClsId);
  165. RegDeleteKey(HKEY_CLASSES_ROOT, wcsSubKey);
  166. wsprintf(wcsSubKey, L"CLSID\\%ws", wcsClsId);
  167. RegDeleteKey(HKEY_CLASSES_ROOT, wcsSubKey);
  168. return S_OK;
  169. }