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.

230 lines
6.4 KiB

  1. /*****************************************************************************
  2. *
  3. * RegSvr.c
  4. *
  5. * Copyright (c) 1996 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * Abstract:
  8. *
  9. * StillImage server OLE self-registration.
  10. *
  11. * Contents:
  12. *
  13. * DllRegisterServer()
  14. * DllUnregisterServer()
  15. *
  16. *****************************************************************************/
  17. #include "pch.h"
  18. VOID
  19. DmPrxyDllRegisterServer(
  20. void
  21. );
  22. VOID
  23. DmPrxyDllUnregisterServer(
  24. void
  25. );
  26. /*****************************************************************************
  27. *
  28. * RegSetStringEx
  29. *
  30. * Add a REG_SZ to hkey\sub::value.
  31. *
  32. *****************************************************************************/
  33. void INTERNAL
  34. RegSetStringEx(HKEY hk, LPCTSTR ptszValue, LPCTSTR ptszData)
  35. {
  36. LONG lRc = RegSetValueEx(hk, ptszValue, 0, REG_SZ,
  37. (PV)ptszData, cbCtch(lstrlen(ptszData)+1));
  38. }
  39. /*****************************************************************************
  40. *
  41. * RegDelStringEx
  42. *
  43. * Remove a REG_SZ from hkey\sub::value. The data is ignored.
  44. * It's passed so that RegDelStringEx matches the prototype for a
  45. * REGSTRINGACTION.
  46. *
  47. *****************************************************************************/
  48. void INTERNAL
  49. RegDelStringEx(HKEY hk, LPCTSTR ptszValue, LPCTSTR ptszData)
  50. {
  51. LONG lRc = RegDeleteValue(hk, ptszValue);
  52. }
  53. /*****************************************************************************
  54. *
  55. * RegCloseFinish
  56. *
  57. * Just close the subkey already.
  58. *
  59. *****************************************************************************/
  60. void INTERNAL
  61. RegCloseFinish(HKEY hk, LPCTSTR ptszSub, HKEY hkSub)
  62. {
  63. LONG lRc = RegCloseKey(hkSub);
  64. }
  65. /*****************************************************************************
  66. *
  67. * RegDelFinish
  68. *
  69. * Delete a key if there is nothing in it.
  70. *
  71. * OLE unregistration rules demand that you not delete a key if OLE
  72. * has added something to it.
  73. *
  74. *****************************************************************************/
  75. void INTERNAL
  76. RegDelFinish(HKEY hk, LPCTSTR ptszSub, HKEY hkSub)
  77. {
  78. LONG lRc;
  79. DWORD cKeys = 0, cValues = 0;
  80. RegQueryInfoKey(hkSub, 0, 0, 0, &cKeys, 0, 0, &cValues, 0, 0, 0, 0);
  81. RegCloseKey(hkSub);
  82. if ((cKeys | cValues) == 0) {
  83. lRc = RegDeleteKey(hk, ptszSub);
  84. } else {
  85. lRc = 0;
  86. }
  87. }
  88. /*****************************************************************************
  89. *
  90. * REGVTBL
  91. *
  92. * Functions for dorking with a registry key, either coming or going.
  93. *
  94. *****************************************************************************/
  95. typedef struct REGVTBL {
  96. /* How to create/open a key */
  97. LONG (INTERNAL *KeyAction)(HKEY hk, LPCTSTR ptszSub, PHKEY phkOut);
  98. /* How to create/delete a string */
  99. void (INTERNAL *StringAction)(HKEY hk, LPCTSTR ptszValue, LPCTSTR ptszData);
  100. /* How to finish using a key */
  101. void (INTERNAL *KeyFinish)(HKEY hk, LPCTSTR ptszSub, HKEY hkSub);
  102. } REGVTBL, *PREGVTBL;
  103. typedef const REGVTBL *PCREGVTBL;
  104. const REGVTBL c_vtblAdd = { RegCreateKey, RegSetStringEx, RegCloseFinish };
  105. const REGVTBL c_vtblDel = { RegOpenKey, RegDelStringEx, RegDelFinish };
  106. /*****************************************************************************
  107. *
  108. * @doc INTERNAL
  109. *
  110. * @func void | DllServerAction |
  111. *
  112. * Register or unregister our objects with OLE/COM/ActiveX/
  113. * whatever its name is.
  114. *
  115. *****************************************************************************/
  116. #pragma BEGIN_CONST_DATA
  117. extern const TCHAR c_tszNil[];
  118. #define ctchClsid ctchGuid
  119. const TCHAR c_tszClsidGuid[] =
  120. TEXT("CLSID\\{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");
  121. const TCHAR c_tszInProcServer32[] = TEXT("InProcServer32");
  122. const TCHAR c_tszThreadingModel[] = TEXT("ThreadingModel");
  123. const TCHAR c_tszBoth[] = TEXT("Both");
  124. #pragma END_CONST_DATA
  125. void INTERNAL
  126. DllServerAction(PCREGVTBL pvtbl)
  127. {
  128. TCHAR tszThisDll[MAX_PATH];
  129. UINT iclsidmap;
  130. GetModuleFileName(g_hInst, tszThisDll, cA(tszThisDll));
  131. for (iclsidmap = 0; iclsidmap < cclsidmap; iclsidmap++) {
  132. TCHAR tszClsid[7+ctchClsid];
  133. HKEY hkClsid;
  134. HKEY hkSub;
  135. REFCLSID rclsid = c_rgclsidmap[iclsidmap].rclsid;
  136. wsprintf(tszClsid, c_tszClsidGuid,
  137. rclsid->Data1, rclsid->Data2, rclsid->Data3,
  138. rclsid->Data4[0], rclsid->Data4[1],
  139. rclsid->Data4[2], rclsid->Data4[3],
  140. rclsid->Data4[4], rclsid->Data4[5],
  141. rclsid->Data4[6], rclsid->Data4[7]);
  142. if (pvtbl->KeyAction(HKEY_CLASSES_ROOT, tszClsid, &hkClsid) == 0) {
  143. TCHAR tszName[127];
  144. /* Do the type name */
  145. LoadString(g_hInst, c_rgclsidmap[iclsidmap].ids,
  146. tszName, cA(tszName));
  147. pvtbl->StringAction(hkClsid, 0, tszName);
  148. /* Do the in-proc server name and threading model */
  149. if (pvtbl->KeyAction(hkClsid, c_tszInProcServer32, &hkSub) == 0) {
  150. pvtbl->StringAction(hkSub, 0, tszThisDll);
  151. pvtbl->StringAction(hkSub, c_tszThreadingModel, c_tszBoth);
  152. pvtbl->KeyFinish(hkClsid, c_tszInProcServer32, hkSub);
  153. }
  154. pvtbl->KeyFinish(HKEY_CLASSES_ROOT, tszClsid, hkClsid);
  155. }
  156. }
  157. }
  158. /*****************************************************************************
  159. *
  160. * @doc INTERNAL
  161. *
  162. * @func void | DllRegisterServer |
  163. *
  164. * Register our classes with OLE/COM/ActiveX/whatever its name is.
  165. *
  166. *****************************************************************************/
  167. void EXTERNAL
  168. DllRegisterServer(void)
  169. {
  170. DmPrxyDllRegisterServer();
  171. //DllServerAction(&c_vtblAdd);
  172. }
  173. /*****************************************************************************
  174. *
  175. * @doc INTERNAL
  176. *
  177. * @func void | DllUnregisterServer |
  178. *
  179. * Unregister our classes from OLE/COM/ActiveX/whatever its name is.
  180. *
  181. *****************************************************************************/
  182. void EXTERNAL
  183. DllUnregisterServer(void)
  184. {
  185. DmPrxyDllUnregisterServer();
  186. //DllServerAction(&c_vtblDel);
  187. }