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.

196 lines
7.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000
  6. //
  7. // File: classreg.h
  8. //
  9. // History: 02-02-2000 Vivekj Added
  10. //--------------------------------------------------------------------------
  11. #pragma once
  12. #ifndef _CLASSREG_H_
  13. #define _CLASSREG_H_
  14. #include "tstring.h"
  15. #include "modulepath.h"
  16. /*+-------------------------------------------------------------------------*
  17. * AddReplacementTrace
  18. *
  19. * Trace helper function.
  20. *--------------------------------------------------------------------------*/
  21. #ifdef DBG
  22. inline void AddReplacementTrace (std::wstring& str, LPCWSTR pszKey, LPCWSTR pszData)
  23. {
  24. if (!str.empty())
  25. str += L"\n";
  26. str += pszKey;
  27. str += L" -> ";
  28. str += pszData;
  29. }
  30. #else
  31. #define AddReplacementTrace(str, pszKey, pszData)
  32. #endif // DBG
  33. /*+-------------------------------------------------------------------------*
  34. * InlineT2W
  35. *
  36. * Helper function to aid in converting tstrings during initialization
  37. * of constant members.
  38. *--------------------------------------------------------------------------*/
  39. inline std::wstring InlineT2W (const tstring& str)
  40. {
  41. #if defined(_UNICODE)
  42. return str;
  43. #else
  44. USES_CONVERSION;
  45. return A2CW(str.c_str());
  46. #endif
  47. }
  48. /*+-------------------------------------------------------------------------*
  49. * CObjectRegParams
  50. *
  51. * Parameters register all objects.
  52. *--------------------------------------------------------------------------*/
  53. class CObjectRegParams
  54. {
  55. public:
  56. CObjectRegParams (
  57. const CLSID& clsid, // CLSID of object
  58. LPCTSTR pszModuleName, // name of implementing DLL
  59. LPCTSTR pszClassName, // class name of object
  60. LPCTSTR pszProgID, // ProgID of object
  61. LPCTSTR pszVersionIndependentProgID, // version-independent ProgID of object
  62. LPCTSTR pszServerType = _T("InprocServer32")) // server type
  63. :
  64. m_clsid (clsid),
  65. m_strModuleName (InlineT2W (pszModuleName) ),
  66. m_strModulePath (InlineT2W ((LPCTSTR)CModulePath::MakeAbsoluteModulePath(pszModuleName))),
  67. m_strClassName (InlineT2W (pszClassName)),
  68. m_strProgID (InlineT2W (pszProgID)),
  69. m_strVersionIndependentProgID (InlineT2W (pszVersionIndependentProgID)),
  70. m_strServerType (InlineT2W (pszServerType))
  71. {
  72. }
  73. const CLSID m_clsid; // CLSID of object
  74. const std::wstring m_strModuleName; // name of implementing DLL
  75. const std::wstring m_strModulePath; // absolute module path
  76. const std::wstring m_strClassName; // class name of object
  77. const std::wstring m_strProgID; // ProgID of object
  78. const std::wstring m_strVersionIndependentProgID; // version-independent ProgID of object
  79. const std::wstring m_strServerType; // server type local/in-proc, etc.
  80. };
  81. /*+-------------------------------------------------------------------------*
  82. * CControlRegParams
  83. *
  84. * Parameters required to register all controls, in addition to
  85. * CObjectRegParams.
  86. *--------------------------------------------------------------------------*/
  87. class CControlRegParams
  88. {
  89. public:
  90. CControlRegParams (
  91. const GUID& libid, // LIBID of control's typelib
  92. LPCTSTR pszToolboxBitmapID, // index of control's bitmap
  93. LPCTSTR pszVersion) // control's version
  94. :
  95. m_libid (libid),
  96. m_strToolboxBitmapID (InlineT2W (pszToolboxBitmapID)),
  97. m_strVersion (InlineT2W (pszVersion))
  98. {
  99. }
  100. const GUID m_libid; // LIBID of control's typelib
  101. const std::wstring m_strToolboxBitmapID; // index of control's bitmap
  102. const std::wstring m_strVersion; // control's version
  103. };
  104. /*+-------------------------------------------------------------------------*
  105. * MMCUpdateRegistry
  106. *
  107. * Registers a COM object or control. This function typically isn't used
  108. * directly, but indirectly via DECLARE_MMC_OBJECT_REGISTRATION or
  109. * DECLARE_MMC_CONTROL_REGISTRATION.
  110. *--------------------------------------------------------------------------*/
  111. MMCBASE_API HRESULT WINAPI MMCUpdateRegistry (
  112. BOOL bRegister, // I:register or unregister?
  113. const CObjectRegParams* pObjParams, // I:object registration parameters
  114. const CControlRegParams* pCtlParams); // I:control registration parameters (optional)
  115. /*+-------------------------------------------------------------------------*
  116. * DECLARE_MMC_OBJECT_REGISTRATION
  117. *
  118. * Declares a registration function for a COM object.
  119. *--------------------------------------------------------------------------*/
  120. #define DECLARE_MMC_OBJECT_REGISTRATION( \
  121. szModule, \
  122. clsid, \
  123. szClassName, \
  124. szProgID, \
  125. szVersionIndependentProgID) \
  126. static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
  127. { \
  128. CObjectRegParams op ( \
  129. clsid, \
  130. szModule, \
  131. szClassName, \
  132. szProgID, \
  133. szVersionIndependentProgID); \
  134. \
  135. return (MMCUpdateRegistry (bRegister, &op, NULL)); \
  136. }
  137. /*+-------------------------------------------------------------------------*
  138. * DECLARE_MMC_CONTROL_REGISTRATION
  139. *
  140. * Declares a registration function for a COM control.
  141. *--------------------------------------------------------------------------*/
  142. #define DECLARE_MMC_CONTROL_REGISTRATION( \
  143. szModule, \
  144. clsid, \
  145. szClassName, \
  146. szProgID, \
  147. szVersionIndependentProgID, \
  148. libid, \
  149. szBitmapID, \
  150. szVersion) \
  151. static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
  152. { \
  153. CObjectRegParams op ( \
  154. clsid, \
  155. szModule, \
  156. szClassName, \
  157. szProgID, \
  158. szVersionIndependentProgID); \
  159. \
  160. CControlRegParams cp ( \
  161. libid, \
  162. szBitmapID, \
  163. szVersion); \
  164. \
  165. return (MMCUpdateRegistry (bRegister, &op, &cp)); \
  166. }
  167. #endif // _CLASSREG_H_