diff options
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Msi/MsiInterop.cs')
-rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Msi/MsiInterop.cs | 571 |
1 files changed, 571 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Msi/MsiInterop.cs b/src/WixToolset.Core.WindowsInstaller/Msi/MsiInterop.cs new file mode 100644 index 00000000..8d195033 --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Msi/MsiInterop.cs | |||
@@ -0,0 +1,571 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolset.Core.WindowsInstaller.Msi | ||
4 | { | ||
5 | using System; | ||
6 | using System.Text; | ||
7 | using System.Runtime.InteropServices; | ||
8 | using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; | ||
9 | using WixToolset.Core.Native; | ||
10 | |||
11 | /// <summary> | ||
12 | /// A callback function that the installer calls for progress notification and error messages. | ||
13 | /// </summary> | ||
14 | /// <param name="context">Pointer to an application context. | ||
15 | /// This parameter can be used for error checking.</param> | ||
16 | /// <param name="messageType">Specifies a combination of one message box style, | ||
17 | /// one message box icon type, one default button, and one installation message type.</param> | ||
18 | /// <param name="message">Specifies the message text.</param> | ||
19 | /// <returns>-1 for an error, 0 if no action was taken, 1 if OK, 3 to abort.</returns> | ||
20 | public delegate int InstallUIHandler(IntPtr context, uint messageType, [MarshalAs(UnmanagedType.LPWStr)] string message); | ||
21 | |||
22 | /// <summary> | ||
23 | /// Enum of predefined persist modes used when opening a database. | ||
24 | /// </summary> | ||
25 | public enum OpenDatabase | ||
26 | { | ||
27 | /// <summary> | ||
28 | /// Open a database read-only, no persistent changes. | ||
29 | /// </summary> | ||
30 | ReadOnly = 0, | ||
31 | |||
32 | /// <summary> | ||
33 | /// Open a database read/write in transaction mode. | ||
34 | /// </summary> | ||
35 | Transact = 1, | ||
36 | |||
37 | /// <summary> | ||
38 | /// Open a database direct read/write without transaction. | ||
39 | /// </summary> | ||
40 | Direct = 2, | ||
41 | |||
42 | /// <summary> | ||
43 | /// Create a new database, transact mode read/write. | ||
44 | /// </summary> | ||
45 | Create = 3, | ||
46 | |||
47 | /// <summary> | ||
48 | /// Create a new database, direct mode read/write. | ||
49 | /// </summary> | ||
50 | CreateDirect = 4, | ||
51 | |||
52 | /// <summary> | ||
53 | /// Indicates a patch file is being opened. | ||
54 | /// </summary> | ||
55 | OpenPatchFile = 32 | ||
56 | } | ||
57 | |||
58 | /// <summary> | ||
59 | /// The errors to suppress when applying a transform. | ||
60 | /// </summary> | ||
61 | [Flags] | ||
62 | public enum TransformErrorConditions | ||
63 | { | ||
64 | /// <summary> | ||
65 | /// None of the following conditions. | ||
66 | /// </summary> | ||
67 | None = 0x0, | ||
68 | |||
69 | /// <summary> | ||
70 | /// Suppress error when adding a row that exists. | ||
71 | /// </summary> | ||
72 | AddExistingRow = 0x1, | ||
73 | |||
74 | /// <summary> | ||
75 | /// Suppress error when deleting a row that does not exist. | ||
76 | /// </summary> | ||
77 | DeleteMissingRow = 0x2, | ||
78 | |||
79 | /// <summary> | ||
80 | /// Suppress error when adding a table that exists. | ||
81 | /// </summary> | ||
82 | AddExistingTable = 0x4, | ||
83 | |||
84 | /// <summary> | ||
85 | /// Suppress error when deleting a table that does not exist. | ||
86 | /// </summary> | ||
87 | DeleteMissingTable = 0x8, | ||
88 | |||
89 | /// <summary> | ||
90 | /// Suppress error when updating a row that does not exist. | ||
91 | /// </summary> | ||
92 | UpdateMissingRow = 0x10, | ||
93 | |||
94 | /// <summary> | ||
95 | /// Suppress error when transform and database code pages do not match, and their code pages are neutral. | ||
96 | /// </summary> | ||
97 | ChangeCodepage = 0x20, | ||
98 | |||
99 | /// <summary> | ||
100 | /// Create the temporary _TransformView table when applying a transform. | ||
101 | /// </summary> | ||
102 | ViewTransform = 0x100, | ||
103 | |||
104 | /// <summary> | ||
105 | /// Suppress all errors but the option to create the temporary _TransformView table. | ||
106 | /// </summary> | ||
107 | All = 0x3F | ||
108 | } | ||
109 | |||
110 | /// <summary> | ||
111 | /// The validation to run while applying a transform. | ||
112 | /// </summary> | ||
113 | [Flags] | ||
114 | public enum TransformValidations | ||
115 | { | ||
116 | /// <summary> | ||
117 | /// Do not validate properties. | ||
118 | /// </summary> | ||
119 | None = 0x0, | ||
120 | |||
121 | /// <summary> | ||
122 | /// Default language must match base database. | ||
123 | /// </summary> | ||
124 | Language = 0x1, | ||
125 | |||
126 | /// <summary> | ||
127 | /// Product must match base database. | ||
128 | /// </summary> | ||
129 | Product = 0x2, | ||
130 | |||
131 | /// <summary> | ||
132 | /// Check major version only. | ||
133 | /// </summary> | ||
134 | MajorVersion = 0x8, | ||
135 | |||
136 | /// <summary> | ||
137 | /// Check major and minor versions only. | ||
138 | /// </summary> | ||
139 | MinorVersion = 0x10, | ||
140 | |||
141 | /// <summary> | ||
142 | /// Check major, minor, and update versions. | ||
143 | /// </summary> | ||
144 | UpdateVersion = 0x20, | ||
145 | |||
146 | /// <summary> | ||
147 | /// Installed version < base version. | ||
148 | /// </summary> | ||
149 | NewLessBaseVersion = 0x40, | ||
150 | |||
151 | /// <summary> | ||
152 | /// Installed version <= base version. | ||
153 | /// </summary> | ||
154 | NewLessEqualBaseVersion = 0x80, | ||
155 | |||
156 | /// <summary> | ||
157 | /// Installed version = base version. | ||
158 | /// </summary> | ||
159 | NewEqualBaseVersion = 0x100, | ||
160 | |||
161 | /// <summary> | ||
162 | /// Installed version >= base version. | ||
163 | /// </summary> | ||
164 | NewGreaterEqualBaseVersion = 0x200, | ||
165 | |||
166 | /// <summary> | ||
167 | /// Installed version > base version. | ||
168 | /// </summary> | ||
169 | NewGreaterBaseVersion = 0x400, | ||
170 | |||
171 | /// <summary> | ||
172 | /// UpgradeCode must match base database. | ||
173 | /// </summary> | ||
174 | UpgradeCode = 0x800 | ||
175 | } | ||
176 | |||
177 | /// <summary> | ||
178 | /// Class exposing static functions and structs from MSI API. | ||
179 | /// </summary> | ||
180 | public sealed class MsiInterop | ||
181 | { | ||
182 | // Patching constants | ||
183 | public const int MsiMaxStreamNameLength = 62; // http://msdn2.microsoft.com/library/aa370551.aspx | ||
184 | |||
185 | public const int MSICONDITIONFALSE = 0; // The table is temporary. | ||
186 | public const int MSICONDITIONTRUE = 1; // The table is persistent. | ||
187 | public const int MSICONDITIONNONE = 2; // The table is unknown. | ||
188 | public const int MSICONDITIONERROR = 3; // An invalid handle or invalid parameter was passed to the function. | ||
189 | /* | ||
190 | public const int MSIDBOPENREADONLY = 0; | ||
191 | public const int MSIDBOPENTRANSACT = 1; | ||
192 | public const int MSIDBOPENDIRECT = 2; | ||
193 | public const int MSIDBOPENCREATE = 3; | ||
194 | public const int MSIDBOPENCREATEDIRECT = 4; | ||
195 | public const int MSIDBOPENPATCHFILE = 32; | ||
196 | |||
197 | public const int MSIMODIFYSEEK = -1; // Refreshes the information in the supplied record without changing the position in the result set and without affecting subsequent fetch operations. The record may then be used for subsequent Update, Delete, and Refresh. All primary key columns of the table must be in the query and the record must have at least as many fields as the query. Seek cannot be used with multi-table queries. This mode cannot be used with a view containing joins. See also the remarks. | ||
198 | public const int MSIMODIFYREFRESH = 0; // Refreshes the information in the record. Must first call MsiViewFetch with the same record. Fails for a deleted row. Works with read-write and read-only records. | ||
199 | public const int MSIMODIFYINSERT = 1; // Inserts a record. Fails if a row with the same primary keys exists. Fails with a read-only database. This mode cannot be used with a view containing joins. | ||
200 | public const int MSIMODIFYUPDATE = 2; // Updates an existing record. Nonprimary keys only. Must first call MsiViewFetch. Fails with a deleted record. Works only with read-write records. | ||
201 | public const int MSIMODIFYASSIGN = 3; // Writes current data in the cursor to a table row. Updates record if the primary keys match an existing row and inserts if they do not match. Fails with a read-only database. This mode cannot be used with a view containing joins. | ||
202 | public const int MSIMODIFYREPLACE = 4; // Updates or deletes and inserts a record into a table. Must first call MsiViewFetch with the same record. Updates record if the primary keys are unchanged. Deletes old row and inserts new if primary keys have changed. Fails with a read-only database. This mode cannot be used with a view containing joins. | ||
203 | public const int MSIMODIFYMERGE = 5; // Inserts or validates a record in a table. Inserts if primary keys do not match any row and validates if there is a match. Fails if the record does not match the data in the table. Fails if there is a record with a duplicate key that is not identical. Works only with read-write records. This mode cannot be used with a view containing joins. | ||
204 | public const int MSIMODIFYDELETE = 6; // Remove a row from the table. You must first call the MsiViewFetch function with the same record. Fails if the row has been deleted. Works only with read-write records. This mode cannot be used with a view containing joins. | ||
205 | public const int MSIMODIFYINSERTTEMPORARY = 7; // Inserts a temporary record. The information is not persistent. Fails if a row with the same primary key exists. Works only with read-write records. This mode cannot be used with a view containing joins. | ||
206 | public const int MSIMODIFYVALIDATE = 8; // Validates a record. Does not validate across joins. You must first call the MsiViewFetch function with the same record. Obtain validation errors with MsiViewGetError. Works with read-write and read-only records. This mode cannot be used with a view containing joins. | ||
207 | public const int MSIMODIFYVALIDATENEW = 9; // Validate a new record. Does not validate across joins. Checks for duplicate keys. Obtain validation errors by calling MsiViewGetError. Works with read-write and read-only records. This mode cannot be used with a view containing joins. | ||
208 | public const int MSIMODIFYVALIDATEFIELD = 10; // Validates fields of a fetched or new record. Can validate one or more fields of an incomplete record. Obtain validation errors by calling MsiViewGetError. Works with read-write and read-only records. This mode cannot be used with a view containing joins. | ||
209 | public const int MSIMODIFYVALIDATEDELETE = 11; // Validates a record that will be deleted later. You must first call MsiViewFetch. Fails if another row refers to the primary keys of this row. Validation does not check for the existence of the primary keys of this row in properties or strings. Does not check if a column is a foreign key to multiple tables. Obtain validation errors by calling MsiViewGetError. Works with read-write and read-only records. This mode cannot be used with a view containing joins. | ||
210 | |||
211 | public const uint VTI2 = 2; | ||
212 | public const uint VTI4 = 3; | ||
213 | public const uint VTLPWSTR = 30; | ||
214 | public const uint VTFILETIME = 64; | ||
215 | */ | ||
216 | |||
217 | public const int MSICOLINFONAMES = 0; // return column names | ||
218 | public const int MSICOLINFOTYPES = 1; // return column definitions, datatype code followed by width | ||
219 | |||
220 | /// <summary> | ||
221 | /// Protect the constructor. | ||
222 | /// </summary> | ||
223 | private MsiInterop() | ||
224 | { | ||
225 | } | ||
226 | |||
227 | /// <summary> | ||
228 | /// PInvoke of MsiCloseHandle. | ||
229 | /// </summary> | ||
230 | /// <param name="database">Handle to a database.</param> | ||
231 | /// <returns>Error code.</returns> | ||
232 | [DllImport("msi.dll", EntryPoint = "MsiCloseHandle", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
233 | public static extern int MsiCloseHandle(uint database); | ||
234 | |||
235 | /// <summary> | ||
236 | /// PInvoke of MsiCreateRecord | ||
237 | /// </summary> | ||
238 | /// <param name="parameters">Count of columns in the record.</param> | ||
239 | /// <returns>Handle referencing the record.</returns> | ||
240 | [DllImport("msi.dll", EntryPoint = "MsiCreateRecord", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
241 | public static extern uint MsiCreateRecord(int parameters); | ||
242 | |||
243 | /// <summary> | ||
244 | /// Creates summary information of an existing transform to include validation and error conditions. | ||
245 | /// </summary> | ||
246 | /// <param name="database">The handle to the database that contains the new database summary information.</param> | ||
247 | /// <param name="referenceDatabase">The handle to the database that contains the original summary information.</param> | ||
248 | /// <param name="transformFile">The name of the transform to which the summary information is added.</param> | ||
249 | /// <param name="errorConditions">The error conditions that should be suppressed when the transform is applied.</param> | ||
250 | /// <param name="validations">Specifies the properties to be validated to verify that the transform can be applied to the database.</param> | ||
251 | /// <returns>Error code.</returns> | ||
252 | [DllImport("msi.dll", EntryPoint = "MsiCreateTransformSummaryInfoW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
253 | public static extern int MsiCreateTransformSummaryInfo(uint database, uint referenceDatabase, string transformFile, TransformErrorConditions errorConditions, TransformValidations validations); | ||
254 | |||
255 | /// <summary> | ||
256 | /// Applies a transform to a database. | ||
257 | /// </summary> | ||
258 | /// <param name="database">Handle to the database obtained from MsiOpenDatabase to transform.</param> | ||
259 | /// <param name="transformFile">Specifies the name of the transform file to apply.</param> | ||
260 | /// <param name="errorConditions">Error conditions that should be suppressed.</param> | ||
261 | /// <returns>Error code.</returns> | ||
262 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseApplyTransformW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
263 | public static extern int MsiDatabaseApplyTransform(uint database, string transformFile, TransformErrorConditions errorConditions); | ||
264 | |||
265 | /// <summary> | ||
266 | /// PInvoke of MsiDatabaseCommit. | ||
267 | /// </summary> | ||
268 | /// <param name="database">Handle to a databse.</param> | ||
269 | /// <returns>Error code.</returns> | ||
270 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseCommit", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
271 | public static extern int MsiDatabaseCommit(uint database); | ||
272 | |||
273 | /// <summary> | ||
274 | /// PInvoke of MsiDatabaseExportW. | ||
275 | /// </summary> | ||
276 | /// <param name="database">Handle to a database.</param> | ||
277 | /// <param name="tableName">Table name.</param> | ||
278 | /// <param name="folderPath">Folder path.</param> | ||
279 | /// <param name="fileName">File name.</param> | ||
280 | /// <returns>Error code.</returns> | ||
281 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseExportW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
282 | public static extern int MsiDatabaseExport(uint database, string tableName, string folderPath, string fileName); | ||
283 | |||
284 | /// <summary> | ||
285 | /// Generates a transform file of differences between two databases. | ||
286 | /// </summary> | ||
287 | /// <param name="database">Handle to the database obtained from MsiOpenDatabase that includes the changes.</param> | ||
288 | /// <param name="databaseReference">Handle to the database obtained from MsiOpenDatabase that does not include the changes.</param> | ||
289 | /// <param name="transformFile">A null-terminated string that specifies the name of the transform file being generated. | ||
290 | /// This parameter can be null. If szTransformFile is null, you can use MsiDatabaseGenerateTransform to test whether two | ||
291 | /// databases are identical without creating a transform. If the databases are identical, the function returns ERROR_NO_DATA. | ||
292 | /// If the databases are different the function returns NOERROR.</param> | ||
293 | /// <param name="reserved1">This is a reserved argument and must be set to 0.</param> | ||
294 | /// <param name="reserved2">This is a reserved argument and must be set to 0.</param> | ||
295 | /// <returns>Error code.</returns> | ||
296 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseGenerateTransformW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
297 | public static extern int MsiDatabaseGenerateTransform(uint database, uint databaseReference, string transformFile, int reserved1, int reserved2); | ||
298 | |||
299 | /// <summary> | ||
300 | /// PInvoke of MsiDatabaseImportW. | ||
301 | /// </summary> | ||
302 | /// <param name="database">Handle to a database.</param> | ||
303 | /// <param name="folderPath">Folder path.</param> | ||
304 | /// <param name="fileName">File name.</param> | ||
305 | /// <returns>Error code.</returns> | ||
306 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseImportW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
307 | public static extern int MsiDatabaseImport(uint database, string folderPath, string fileName); | ||
308 | |||
309 | /// <summary> | ||
310 | /// PInvoke of MsiDatabaseMergeW. | ||
311 | /// </summary> | ||
312 | /// <param name="database">The handle to the database obtained from MsiOpenDatabase.</param> | ||
313 | /// <param name="databaseMerge">The handle to the database obtained from MsiOpenDatabase to merge into the base database.</param> | ||
314 | /// <param name="tableName">The name of the table to receive merge conflict information.</param> | ||
315 | /// <returns>Error code.</returns> | ||
316 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseMergeW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
317 | public static extern int MsiDatabaseMerge(uint database, uint databaseMerge, string tableName); | ||
318 | |||
319 | /// <summary> | ||
320 | /// PInvoke of MsiDatabaseOpenViewW. | ||
321 | /// </summary> | ||
322 | /// <param name="database">Handle to a database.</param> | ||
323 | /// <param name="query">SQL query.</param> | ||
324 | /// <param name="view">View handle.</param> | ||
325 | /// <returns>Error code.</returns> | ||
326 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseOpenViewW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
327 | public static extern int MsiDatabaseOpenView(uint database, string query, out uint view); | ||
328 | |||
329 | /// <summary> | ||
330 | /// PInvoke of MsiGetFileHashW. | ||
331 | /// </summary> | ||
332 | /// <param name="filePath">File path.</param> | ||
333 | /// <param name="options">Hash options (must be 0).</param> | ||
334 | /// <param name="hash">Buffer to recieve hash.</param> | ||
335 | /// <returns>Error code.</returns> | ||
336 | [DllImport("msi.dll", EntryPoint = "MsiGetFileHashW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
337 | public static extern int MsiGetFileHash(string filePath, uint options, MSIFILEHASHINFO hash); | ||
338 | |||
339 | /// <summary> | ||
340 | /// PInvoke of MsiGetFileVersionW. | ||
341 | /// </summary> | ||
342 | /// <param name="filePath">File path.</param> | ||
343 | /// <param name="versionBuf">Buffer to receive version info.</param> | ||
344 | /// <param name="versionBufSize">Size of version buffer.</param> | ||
345 | /// <param name="langBuf">Buffer to recieve lang info.</param> | ||
346 | /// <param name="langBufSize">Size of lang buffer.</param> | ||
347 | /// <returns>Error code.</returns> | ||
348 | [DllImport("msi.dll", EntryPoint = "MsiGetFileVersionW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
349 | public static extern int MsiGetFileVersion(string filePath, StringBuilder versionBuf, ref int versionBufSize, StringBuilder langBuf, ref int langBufSize); | ||
350 | |||
351 | /// <summary> | ||
352 | /// PInvoke of MsiGetLastErrorRecord. | ||
353 | /// </summary> | ||
354 | /// <returns>Handle to error record if one exists.</returns> | ||
355 | [DllImport("msi.dll", EntryPoint = "MsiGetLastErrorRecord", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
356 | public static extern uint MsiGetLastErrorRecord(); | ||
357 | |||
358 | /// <summary> | ||
359 | /// PInvoke of MsiDatabaseGetPrimaryKeysW. | ||
360 | /// </summary> | ||
361 | /// <param name="database">Handle to a database.</param> | ||
362 | /// <param name="tableName">Table name.</param> | ||
363 | /// <param name="record">Handle to receive resulting record.</param> | ||
364 | /// <returns>Error code.</returns> | ||
365 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseGetPrimaryKeysW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
366 | public static extern int MsiDatabaseGetPrimaryKeys(uint database, string tableName, out uint record); | ||
367 | |||
368 | /// <summary> | ||
369 | /// PInvoke of MsiDoActionW. | ||
370 | /// </summary> | ||
371 | /// <param name="product">Handle to the installation provided to a DLL custom action or | ||
372 | /// obtained through MsiOpenPackage, MsiOpenPackageEx, or MsiOpenProduct.</param> | ||
373 | /// <param name="action">Specifies the action to execute.</param> | ||
374 | /// <returns>Error code.</returns> | ||
375 | [DllImport("msi.dll", EntryPoint = "MsiDoActionW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
376 | public static extern int MsiDoAction(uint product, string action); | ||
377 | |||
378 | /// <summary> | ||
379 | /// PInvoke of MsiGetSummaryInformationW. Can use either database handle or database path as input. | ||
380 | /// </summary> | ||
381 | /// <param name="database">Handle to a database.</param> | ||
382 | /// <param name="databasePath">Path to a database.</param> | ||
383 | /// <param name="updateCount">Max number of updated values.</param> | ||
384 | /// <param name="summaryInfo">Handle to summary information.</param> | ||
385 | /// <returns>Error code.</returns> | ||
386 | [DllImport("msi.dll", EntryPoint = "MsiGetSummaryInformationW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
387 | public static extern int MsiGetSummaryInformation(uint database, string databasePath, uint updateCount, ref uint summaryInfo); | ||
388 | |||
389 | /// <summary> | ||
390 | /// PInvoke of MsiDatabaseIsTablePersitentW. | ||
391 | /// </summary> | ||
392 | /// <param name="database">Handle to a database.</param> | ||
393 | /// <param name="tableName">Table name.</param> | ||
394 | /// <returns>MSICONDITION</returns> | ||
395 | [DllImport("msi.dll", EntryPoint = "MsiDatabaseIsTablePersistentW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
396 | public static extern int MsiDatabaseIsTablePersistent(uint database, string tableName); | ||
397 | |||
398 | /// <summary> | ||
399 | /// PInvoke of MsiOpenDatabaseW. | ||
400 | /// </summary> | ||
401 | /// <param name="databasePath">Path to database.</param> | ||
402 | /// <param name="persist">Persist mode.</param> | ||
403 | /// <param name="database">Handle to database.</param> | ||
404 | /// <returns>Error code.</returns> | ||
405 | [DllImport("msi.dll", EntryPoint = "MsiOpenDatabaseW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
406 | public static extern int MsiOpenDatabase(string databasePath, IntPtr persist, out uint database); | ||
407 | |||
408 | /// <summary> | ||
409 | /// PInvoke of MsiOpenPackageW. | ||
410 | /// </summary> | ||
411 | /// <param name="packagePath">The path to the package.</param> | ||
412 | /// <param name="product">A pointer to a variable that receives the product handle.</param> | ||
413 | /// <returns>Error code.</returns> | ||
414 | [DllImport("msi.dll", EntryPoint = "MsiOpenPackageW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
415 | public static extern int MsiOpenPackage(string packagePath, out uint product); | ||
416 | |||
417 | /// <summary> | ||
418 | /// PInvoke of MsiRecordIsNull. | ||
419 | /// </summary> | ||
420 | /// <param name="record">MSI Record handle.</param> | ||
421 | /// <param name="field">Index of field to check for null value.</param> | ||
422 | /// <returns>true if the field is null, false if not, and an error code for any error.</returns> | ||
423 | [DllImport("msi.dll", EntryPoint = "MsiRecordIsNull", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
424 | public static extern int MsiRecordIsNull(uint record, int field); | ||
425 | |||
426 | /// <summary> | ||
427 | /// PInvoke of MsiRecordGetInteger. | ||
428 | /// </summary> | ||
429 | /// <param name="record">MSI Record handle.</param> | ||
430 | /// <param name="field">Index of field to retrieve integer from.</param> | ||
431 | /// <returns>Integer value.</returns> | ||
432 | [DllImport("msi.dll", EntryPoint = "MsiRecordGetInteger", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
433 | public static extern int MsiRecordGetInteger(uint record, int field); | ||
434 | |||
435 | /// <summary> | ||
436 | /// PInvoke of MsiRectordSetInteger. | ||
437 | /// </summary> | ||
438 | /// <param name="record">MSI Record handle.</param> | ||
439 | /// <param name="field">Index of field to set integer value in.</param> | ||
440 | /// <param name="value">Value to set field to.</param> | ||
441 | /// <returns>Error code.</returns> | ||
442 | [DllImport("msi.dll", EntryPoint = "MsiRecordSetInteger", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
443 | public static extern int MsiRecordSetInteger(uint record, int field, int value); | ||
444 | |||
445 | /// <summary> | ||
446 | /// PInvoke of MsiRecordGetStringW. | ||
447 | /// </summary> | ||
448 | /// <param name="record">MSI Record handle.</param> | ||
449 | /// <param name="field">Index of field to get string value from.</param> | ||
450 | /// <param name="valueBuf">Buffer to recieve value.</param> | ||
451 | /// <param name="valueBufSize">Size of buffer.</param> | ||
452 | /// <returns>Error code.</returns> | ||
453 | [DllImport("msi.dll", EntryPoint = "MsiRecordGetStringW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
454 | public static extern int MsiRecordGetString(uint record, int field, StringBuilder valueBuf, ref int valueBufSize); | ||
455 | |||
456 | /// <summary> | ||
457 | /// PInvoke of MsiRecordSetStringW. | ||
458 | /// </summary> | ||
459 | /// <param name="record">MSI Record handle.</param> | ||
460 | /// <param name="field">Index of field to set string value in.</param> | ||
461 | /// <param name="value">String value.</param> | ||
462 | /// <returns>Error code.</returns> | ||
463 | [DllImport("msi.dll", EntryPoint = "MsiRecordSetStringW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
464 | public static extern int MsiRecordSetString(uint record, int field, string value); | ||
465 | |||
466 | /// <summary> | ||
467 | /// PInvoke of MsiRecordSetStreamW. | ||
468 | /// </summary> | ||
469 | /// <param name="record">MSI Record handle.</param> | ||
470 | /// <param name="field">Index of field to set stream value in.</param> | ||
471 | /// <param name="filePath">Path to file to set stream value to.</param> | ||
472 | /// <returns>Error code.</returns> | ||
473 | [DllImport("msi.dll", EntryPoint = "MsiRecordSetStreamW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
474 | public static extern int MsiRecordSetStream(uint record, int field, string filePath); | ||
475 | |||
476 | /// <summary> | ||
477 | /// PInvoke of MsiRecordReadStreamW. | ||
478 | /// </summary> | ||
479 | /// <param name="record">MSI Record handle.</param> | ||
480 | /// <param name="field">Index of field to read stream from.</param> | ||
481 | /// <param name="dataBuf">Data buffer to recieve stream value.</param> | ||
482 | /// <param name="dataBufSize">Size of data buffer.</param> | ||
483 | /// <returns>Error code.</returns> | ||
484 | [DllImport("msi.dll", EntryPoint = "MsiRecordReadStream", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
485 | public static extern int MsiRecordReadStream(uint record, int field, byte[] dataBuf, ref int dataBufSize); | ||
486 | |||
487 | /// <summary> | ||
488 | /// PInvoke of MsiRecordGetFieldCount. | ||
489 | /// </summary> | ||
490 | /// <param name="record">MSI Record handle.</param> | ||
491 | /// <returns>Count of fields in the record.</returns> | ||
492 | [DllImport("msi.dll", EntryPoint = "MsiRecordGetFieldCount", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
493 | public static extern int MsiRecordGetFieldCount(uint record); | ||
494 | |||
495 | /// <summary> | ||
496 | /// PInvoke of MsiSetExternalUIW. | ||
497 | /// </summary> | ||
498 | /// <param name="installUIHandler">Specifies a callback function that conforms to the INSTALLUI_HANDLER specification.</param> | ||
499 | /// <param name="installLogMode">Specifies which messages to handle using the external message handler. If the external | ||
500 | /// handler returns a non-zero result, then that message will not be sent to the UI, instead the message will be logged | ||
501 | /// if logging has been enabled.</param> | ||
502 | /// <param name="context">Pointer to an application context that is passed to the callback function. | ||
503 | /// This parameter can be used for error checking.</param> | ||
504 | /// <returns>The return value is the previously set external handler, or zero (0) if there was no previously set handler.</returns> | ||
505 | [DllImport("msi.dll", EntryPoint = "MsiSetExternalUIW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
506 | public static extern InstallUIHandler MsiSetExternalUI(InstallUIHandler installUIHandler, int installLogMode, IntPtr context); | ||
507 | |||
508 | /// <summary> | ||
509 | /// PInvoke of MsiSetpublicUI. | ||
510 | /// </summary> | ||
511 | /// <param name="uiLevel">Specifies the level of complexity of the user interface.</param> | ||
512 | /// <param name="hwnd">Pointer to a window. This window becomes the owner of any user interface created. | ||
513 | /// A pointer to the previous owner of the user interface is returned. | ||
514 | /// If this parameter is null, the owner of the user interface does not change.</param> | ||
515 | /// <returns>The previous user interface level is returned. If an invalid dwUILevel is passed, then INSTALLUILEVEL_NOCHANGE is returned.</returns> | ||
516 | [DllImport("msi.dll", EntryPoint = "MsiSetpublicUI", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
517 | public static extern int MsiSetInternalUI(int uiLevel, ref IntPtr hwnd); | ||
518 | |||
519 | /// <summary> | ||
520 | /// PInvoke of MsiSummaryInfoGetPropertyW. | ||
521 | /// </summary> | ||
522 | /// <param name="summaryInfo">Handle to summary info.</param> | ||
523 | /// <param name="property">Property to get value from.</param> | ||
524 | /// <param name="dataType">Data type of property.</param> | ||
525 | /// <param name="integerValue">Integer to receive integer value.</param> | ||
526 | /// <param name="fileTimeValue">File time to receive file time value.</param> | ||
527 | /// <param name="stringValueBuf">String buffer to receive string value.</param> | ||
528 | /// <param name="stringValueBufSize">Size of string buffer.</param> | ||
529 | /// <returns>Error code.</returns> | ||
530 | [DllImport("msi.dll", EntryPoint = "MsiSummaryInfoGetPropertyW", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
531 | public static extern int MsiSummaryInfoGetProperty(uint summaryInfo, int property, out uint dataType, out int integerValue, ref FILETIME fileTimeValue, StringBuilder stringValueBuf, ref int stringValueBufSize); | ||
532 | |||
533 | /// <summary> | ||
534 | /// PInvoke of MsiViewGetColumnInfo. | ||
535 | /// </summary> | ||
536 | /// <param name="view">Handle to view.</param> | ||
537 | /// <param name="columnInfo">Column info.</param> | ||
538 | /// <param name="record">Handle for returned record.</param> | ||
539 | /// <returns>Error code.</returns> | ||
540 | [DllImport("msi.dll", EntryPoint = "MsiViewGetColumnInfo", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
541 | public static extern int MsiViewGetColumnInfo(uint view, int columnInfo, out uint record); | ||
542 | |||
543 | /// <summary> | ||
544 | /// PInvoke of MsiViewExecute. | ||
545 | /// </summary> | ||
546 | /// <param name="view">Handle of view to execute.</param> | ||
547 | /// <param name="record">Handle to a record that supplies the parameters for the view.</param> | ||
548 | /// <returns>Error code.</returns> | ||
549 | [DllImport("msi.dll", EntryPoint = "MsiViewExecute", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
550 | public static extern int MsiViewExecute(uint view, uint record); | ||
551 | |||
552 | /// <summary> | ||
553 | /// PInvoke of MsiViewFetch. | ||
554 | /// </summary> | ||
555 | /// <param name="view">Handle of view to fetch a row from.</param> | ||
556 | /// <param name="record">Handle to receive record info.</param> | ||
557 | /// <returns>Error code.</returns> | ||
558 | [DllImport("msi.dll", EntryPoint = "MsiViewFetch", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
559 | public static extern int MsiViewFetch(uint view, out uint record); | ||
560 | |||
561 | /// <summary> | ||
562 | /// PInvoke of MsiViewModify. | ||
563 | /// </summary> | ||
564 | /// <param name="view">Handle of view to modify.</param> | ||
565 | /// <param name="modifyMode">Modify mode.</param> | ||
566 | /// <param name="record">Handle of record.</param> | ||
567 | /// <returns>Error code.</returns> | ||
568 | [DllImport("msi.dll", EntryPoint = "MsiViewModify", CharSet = CharSet.Unicode, ExactSpelling = true)] | ||
569 | public static extern int MsiViewModify(uint view, int modifyMode, uint record); | ||
570 | } | ||
571 | } | ||