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.

296 lines
9.1 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2001.
  5. //
  6. // File: msibase.h
  7. //
  8. // Contents: msi database abstractions
  9. //
  10. // History: 4-14-2000 adamed Created
  11. //
  12. //---------------------------------------------------------------------------
  13. #if !defined(__MSIBASE_H__)
  14. #define __MSIBASE_H__
  15. //
  16. // Module Notes
  17. //
  18. // Class Relational Overview
  19. //
  20. // Below we describe how the classes declared in this module
  21. // relate to each other -- the --> notation indicates the "yields" relation:
  22. //
  23. // - A path to an MSI package --> CMsiDatabase: A path to an MSI package, along
  24. // with a set of transforms, can be used to instantiate a CMsiDatabase
  25. // object that abstracts the package with a database style view.
  26. //
  27. // - CMsiDatabase --> CMsiQuery: a CMsiDatabase allows one to retrieve
  28. // queries against the database (MSI package).
  29. //
  30. // - CMsiQuery --> CMsiRecord: a CMsiQuery allows one to retrieve or
  31. // alter records that are part of the results of the msi database query.
  32. //
  33. // - CMsiRecord --> CMsiValue: a CMsiValue allows the retrieval of
  34. // individual values of an MSI database record.
  35. //
  36. // -CMsiState is a base class for the classes above that maintain
  37. // MSI database engine state (e.g. msi handles) -- this class
  38. // has no direct utility to classes outside this module
  39. //
  40. //-------------------------------------------------------------------------------------
  41. //
  42. // Class sequential Overview:
  43. //
  44. // The following sequence is typical of the use of the classes envisioned
  45. // in the design of this module:
  46. //
  47. // 1. CMsiDatabase: Instantiate a CMsiDatabase object, and call its Open method
  48. // in order to get a database view of a particular package.
  49. // 2. CMsiQuery: Use the GetQueryResults method to place the results of a query into
  50. // a CMsiQuery which was passed into the call as an out parameter,
  51. // or use the OpenQuery method to start a query without retrieving results
  52. // immediately (they can be retrieved later). The latter is useful
  53. // when performing queries that need to update a single record -- you
  54. // use OpenQuery with a query string that allows the results records to be changed,
  55. // then call the UpdateQueryFromFilter method of CMsiQuery in order to
  56. // alter a record.
  57. // 3. CMsiRecord: Use the GetNextRecord methods of CMsiQuery to retrieve a
  58. // CMsiRecord that represents a record from the query.
  59. // 4. CMsiValue: Use the GetValue method of CMsiRecord to retrieve a particular
  60. // value of the msi record.
  61. //
  62. //
  63. // For information on the individual methods of each class, please see the source
  64. // file where the methods are implemented.
  65. //
  66. #if defined(DBG)
  67. #define DEFAULT_STRING_SIZE 16
  68. #else // defined(DBG)
  69. #define DEFAULT_STRING_SIZE 256
  70. #endif // defined(DBG)
  71. //+--------------------------------------------------------------------------
  72. //
  73. // Class: CMsiState
  74. //
  75. // Synopsis: class that encapsulates an msi handle. It ensures that
  76. // the handle is freed when instances of the class are destroyed.
  77. //
  78. // Notes: this class is generally only needed by classes in this module --
  79. // it has no useful methods for classes outside this module
  80. //
  81. //---------------------------------------------------------------------------
  82. class CMsiState
  83. {
  84. public:
  85. CMsiState();
  86. ~CMsiState();
  87. void
  88. SetState( MSIHANDLE pMsiHandle );
  89. MSIHANDLE
  90. GetState();
  91. private:
  92. MSIHANDLE _MsiHandle;
  93. };
  94. //+--------------------------------------------------------------------------
  95. //
  96. // Class: CMsiValue
  97. //
  98. // Synopsis: Class that encapsulates values that can be returned by
  99. // a record of an msi database. It ensures that resources (e.g. memory)
  100. // associated with instances of the class are freed when the class is
  101. // destroyed. It also attempts to avoid heap allocation in favor of
  102. // stack allocation when possible -- this is abstracted from the consumer
  103. //
  104. // Notes: This class is designed to be used as follows:
  105. // 1. Declare an instance of this class on the stack
  106. // 2. Pass a reference to the instance to a function which takes
  107. // a reference to this class as an out parameter.
  108. // 3. The function that is called will "fill in" the value using
  109. // the Set methods of this class.
  110. // 4. The caller may then use Get methods to retrieve the value
  111. // in a useful form (such as DWORD or WCHAR*).
  112. //
  113. //---------------------------------------------------------------------------
  114. class CMsiValue
  115. {
  116. public:
  117. enum
  118. {
  119. TYPE_NOT_SET,
  120. TYPE_DWORD,
  121. TYPE_STRING
  122. };
  123. CMsiValue();
  124. ~CMsiValue();
  125. DWORD
  126. GetDWORDValue();
  127. WCHAR*
  128. GetStringValue();
  129. DWORD
  130. GetStringSize();
  131. WCHAR*
  132. DuplicateString();
  133. void
  134. SetDWORDValue( DWORD dwValue );
  135. LONG
  136. SetStringValue( WCHAR* wszValue );
  137. LONG
  138. SetStringSize( DWORD cchSize );
  139. void
  140. SetType( DWORD dwType );
  141. private:
  142. WCHAR _wszDefaultBuf[DEFAULT_STRING_SIZE];
  143. DWORD _dwDiscriminant;
  144. WCHAR* _wszValue;
  145. DWORD _cchSize;
  146. DWORD _dwValue;
  147. };
  148. //+--------------------------------------------------------------------------
  149. //
  150. // Class: CMsiRecord
  151. //
  152. // Synopsis: Class that encapsulates msi database records. It ensures
  153. // that any state (e.g. msi handle) associated with an instance of
  154. // this class will be freed when the instance is destroyed.
  155. //
  156. // Notes: This class is designed to be used as follows:
  157. // 1. Declare an instance of this class on the stack
  158. // 2. Pass a reference to the instance to a function which takes
  159. // a reference to this class as an out parameter.
  160. // 3. The function that is called will "fill in" the value using
  161. // the SetState method of this class.
  162. // 4. The caller may then use the GetValue method to retrieve individual
  163. // values of the record, which in turn may be converted into
  164. // concrete data types (see the CMsiValue class).
  165. //
  166. //---------------------------------------------------------------------------
  167. class CMsiRecord : public CMsiState
  168. {
  169. public:
  170. LONG
  171. GetValue(
  172. DWORD dwType,
  173. DWORD dwValue,
  174. CMsiValue* pMsiValue);
  175. };
  176. //+--------------------------------------------------------------------------
  177. //
  178. // Class: CMsiQuery
  179. //
  180. // Synopsis: Class that encapsulates msi database queries. It ensures
  181. // that any state (e.g. msi handle) associated with an instance of
  182. // this class will be freed when the instance is destroyed.
  183. //
  184. // Notes: This class is designed to be used as follows:
  185. // 1. Declare an instance of this class on the stack
  186. // 2. Pass a reference to the instance to a function which takes
  187. // a reference to this class as an out parameter.
  188. // 3. The function that is called will "fill in" the value using
  189. // the SetState method of this class.
  190. // 4. The caller may then use the GetNextRecord method to retrieve a
  191. // record from the results of the query, or use the
  192. // UpdateQueryFromFilter method to alter one of the records in
  193. // the query.
  194. //
  195. //---------------------------------------------------------------------------
  196. class CMsiQuery : public CMsiState
  197. {
  198. public:
  199. LONG
  200. GetNextRecord( CMsiRecord* pMsiRecord );
  201. LONG
  202. UpdateQueryFromFilter( CMsiRecord* pFilterRecord );
  203. };
  204. //+--------------------------------------------------------------------------
  205. //
  206. // Class: CMsiDatabase
  207. //
  208. // Synopsis: Class that an msi database (package). It ensures
  209. // that any state (e.g. msi handle) associated with an instance of
  210. // this class will be freed when the instance is destroyed.
  211. //
  212. // Notes: This class is designed to be used as follows:
  213. // 1. Create an instance of this class
  214. // 2. Use the Open method to gain access to a package + set of transforms
  215. // as a database that can be queried
  216. // 3. To create and retrieve results of a query on an opened database,
  217. // Use the GetQueryResults method
  218. // 4. To create a query (but not retrieve its results), use the OpenQuery
  219. // method. This is useful with when the query's UpdateQueryFromFilter
  220. // method is used to change an individual record, rather than retrieving
  221. // a result set (a la GetQueryResults).
  222. //
  223. //---------------------------------------------------------------------------
  224. class CMsiDatabase : public CMsiState
  225. {
  226. public:
  227. LONG
  228. Open(
  229. WCHAR* wszPath,
  230. DWORD cTransforms,
  231. WCHAR** rgwszTransforms);
  232. LONG
  233. GetQueryResults(
  234. WCHAR* wszQuery,
  235. CMsiQuery* pQuery );
  236. LONG
  237. OpenQuery(
  238. WCHAR* wszQuery,
  239. CMsiQuery* pQuery);
  240. LONG
  241. TableExists(
  242. WCHAR* wszTableName,
  243. BOOL* pbTableExists );
  244. };
  245. #endif // __MSIBASE_H__