diff options
Diffstat (limited to 'src/dtf/WixToolset.Dtf.WindowsInstaller/RemotableNativeMethods.cs')
| -rw-r--r-- | src/dtf/WixToolset.Dtf.WindowsInstaller/RemotableNativeMethods.cs | 1171 |
1 files changed, 1171 insertions, 0 deletions
diff --git a/src/dtf/WixToolset.Dtf.WindowsInstaller/RemotableNativeMethods.cs b/src/dtf/WixToolset.Dtf.WindowsInstaller/RemotableNativeMethods.cs new file mode 100644 index 00000000..960fd15f --- /dev/null +++ b/src/dtf/WixToolset.Dtf.WindowsInstaller/RemotableNativeMethods.cs | |||
| @@ -0,0 +1,1171 @@ | |||
| 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.Dtf.WindowsInstaller | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Text; | ||
| 7 | using System.Runtime.InteropServices; | ||
| 8 | using System.Diagnostics.CodeAnalysis; | ||
| 9 | |||
| 10 | /// <summary> | ||
| 11 | /// Assigns ID numbers to the MSI APIs that are remotable. | ||
| 12 | /// </summary> | ||
| 13 | /// <remarks><p> | ||
| 14 | /// This enumeration MUST stay in sync with the | ||
| 15 | /// unmanaged equivalent in RemoteMsiSession.h! | ||
| 16 | /// </p></remarks> | ||
| 17 | internal enum RemoteMsiFunctionId | ||
| 18 | { | ||
| 19 | EndSession = 0, | ||
| 20 | MsiCloseHandle, | ||
| 21 | MsiCreateRecord, | ||
| 22 | MsiDatabaseGetPrimaryKeys, | ||
| 23 | MsiDatabaseIsTablePersistent, | ||
| 24 | MsiDatabaseOpenView, | ||
| 25 | MsiDoAction, | ||
| 26 | MsiEnumComponentCosts, | ||
| 27 | MsiEvaluateCondition, | ||
| 28 | MsiFormatRecord, | ||
| 29 | MsiGetActiveDatabase, | ||
| 30 | MsiGetComponentState, | ||
| 31 | MsiGetFeatureCost, | ||
| 32 | MsiGetFeatureState, | ||
| 33 | MsiGetFeatureValidStates, | ||
| 34 | MsiGetLanguage, | ||
| 35 | MsiGetLastErrorRecord, | ||
| 36 | MsiGetMode, | ||
| 37 | MsiGetProperty, | ||
| 38 | MsiGetSourcePath, | ||
| 39 | MsiGetSummaryInformation, | ||
| 40 | MsiGetTargetPath, | ||
| 41 | MsiProcessMessage, | ||
| 42 | MsiRecordClearData, | ||
| 43 | MsiRecordDataSize, | ||
| 44 | MsiRecordGetFieldCount, | ||
| 45 | MsiRecordGetInteger, | ||
| 46 | MsiRecordGetString, | ||
| 47 | MsiRecordIsNull, | ||
| 48 | MsiRecordReadStream, | ||
| 49 | MsiRecordSetInteger, | ||
| 50 | MsiRecordSetStream, | ||
| 51 | MsiRecordSetString, | ||
| 52 | MsiSequence, | ||
| 53 | MsiSetComponentState, | ||
| 54 | MsiSetFeatureAttributes, | ||
| 55 | MsiSetFeatureState, | ||
| 56 | MsiSetInstallLevel, | ||
| 57 | MsiSetMode, | ||
| 58 | MsiSetProperty, | ||
| 59 | MsiSetTargetPath, | ||
| 60 | MsiSummaryInfoGetProperty, | ||
| 61 | MsiVerifyDiskSpace, | ||
| 62 | MsiViewExecute, | ||
| 63 | MsiViewFetch, | ||
| 64 | MsiViewGetError, | ||
| 65 | MsiViewGetColumnInfo, | ||
| 66 | MsiViewModify, | ||
| 67 | } | ||
| 68 | |||
| 69 | /// <summary> | ||
| 70 | /// Defines the signature of the native function | ||
| 71 | /// in SfxCA.dll that implements the remoting call. | ||
| 72 | /// </summary> | ||
| 73 | internal delegate void MsiRemoteInvoke( | ||
| 74 | RemoteMsiFunctionId id, | ||
| 75 | [MarshalAs(UnmanagedType.SysInt)] | ||
| 76 | IntPtr request, | ||
| 77 | [MarshalAs(UnmanagedType.SysInt)] | ||
| 78 | out IntPtr response); | ||
| 79 | |||
| 80 | /// <summary> | ||
| 81 | /// Redirects native API calls to either the normal NativeMethods class | ||
| 82 | /// or to out-of-proc calls via the remoting channel. | ||
| 83 | /// </summary> | ||
| 84 | internal static class RemotableNativeMethods | ||
| 85 | { | ||
| 86 | private const int MAX_REQUEST_FIELDS = 4; | ||
| 87 | private static int requestFieldDataOffset; | ||
| 88 | private static int requestFieldSize; | ||
| 89 | |||
| 90 | [SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] | ||
| 91 | private static IntPtr requestBuf; | ||
| 92 | |||
| 93 | private static MsiRemoteInvoke remotingDelegate; | ||
| 94 | |||
| 95 | /// <summary> | ||
| 96 | /// Checks if the current process is using remoting to access the | ||
| 97 | /// MSI session and database APIs. | ||
| 98 | /// </summary> | ||
| 99 | internal static bool RemotingEnabled | ||
| 100 | { | ||
| 101 | get | ||
| 102 | { | ||
| 103 | return RemotableNativeMethods.remotingDelegate != null; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | /// <summary> | ||
| 108 | /// Sets a delegate that is used to make remote API calls. | ||
| 109 | /// </summary> | ||
| 110 | /// <remarks><p> | ||
| 111 | /// The implementation of this delegate is provided by the | ||
| 112 | /// custom action host DLL. | ||
| 113 | /// </p></remarks> | ||
| 114 | [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] | ||
| 115 | internal static MsiRemoteInvoke RemotingDelegate | ||
| 116 | { | ||
| 117 | set | ||
| 118 | { | ||
| 119 | RemotableNativeMethods.remotingDelegate = value; | ||
| 120 | |||
| 121 | if (value != null && requestBuf == IntPtr.Zero) | ||
| 122 | { | ||
| 123 | requestFieldDataOffset = Marshal.SizeOf(typeof(IntPtr)); | ||
| 124 | requestFieldSize = 2 * Marshal.SizeOf(typeof(IntPtr)); | ||
| 125 | RemotableNativeMethods.requestBuf = Marshal.AllocHGlobal( | ||
| 126 | requestFieldSize * MAX_REQUEST_FIELDS); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | internal static bool IsRemoteHandle(int handle) | ||
| 132 | { | ||
| 133 | return (handle & Int32.MinValue) != 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | internal static int MakeRemoteHandle(int handle) | ||
| 137 | { | ||
| 138 | if (handle == 0) | ||
| 139 | { | ||
| 140 | return handle; | ||
| 141 | } | ||
| 142 | |||
| 143 | if (RemotableNativeMethods.IsRemoteHandle(handle)) | ||
| 144 | { | ||
| 145 | throw new InvalidOperationException("Handle already has the remote bit set."); | ||
| 146 | } | ||
| 147 | |||
| 148 | return handle ^ Int32.MinValue; | ||
| 149 | } | ||
| 150 | |||
| 151 | internal static int GetRemoteHandle(int handle) | ||
| 152 | { | ||
| 153 | if (handle == 0) | ||
| 154 | { | ||
| 155 | return handle; | ||
| 156 | } | ||
| 157 | |||
| 158 | if (!RemotableNativeMethods.IsRemoteHandle(handle)) | ||
| 159 | { | ||
| 160 | throw new InvalidOperationException("Handle does not have the remote bit set."); | ||
| 161 | } | ||
| 162 | |||
| 163 | return handle ^ Int32.MinValue; | ||
| 164 | } | ||
| 165 | |||
| 166 | private static void ClearData(IntPtr buf) | ||
| 167 | { | ||
| 168 | for (int i = 0; i < MAX_REQUEST_FIELDS; i++) | ||
| 169 | { | ||
| 170 | Marshal.WriteInt32(buf, (i * requestFieldSize), (int) VarEnum.VT_NULL); | ||
| 171 | Marshal.WriteIntPtr(buf, (i * requestFieldSize) + requestFieldDataOffset, IntPtr.Zero); | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | private static void WriteInt(IntPtr buf, int field, int value) | ||
| 176 | { | ||
| 177 | Marshal.WriteInt32(buf, (field * requestFieldSize), (int) VarEnum.VT_I4); | ||
| 178 | Marshal.WriteInt32(buf, (field * requestFieldSize) + requestFieldDataOffset, value); | ||
| 179 | } | ||
| 180 | |||
| 181 | private static void WriteString(IntPtr buf, int field, string value) | ||
| 182 | { | ||
| 183 | if (value == null) | ||
| 184 | { | ||
| 185 | Marshal.WriteInt32(buf, (field * requestFieldSize), (int) VarEnum.VT_NULL); | ||
| 186 | Marshal.WriteIntPtr(buf, (field * requestFieldSize) + requestFieldDataOffset, IntPtr.Zero); | ||
| 187 | } | ||
| 188 | else | ||
| 189 | { | ||
| 190 | IntPtr stringPtr = Marshal.StringToHGlobalUni(value); | ||
| 191 | Marshal.WriteInt32(buf, (field * requestFieldSize), (int) VarEnum.VT_LPWSTR); | ||
| 192 | Marshal.WriteIntPtr(buf, (field * requestFieldSize) + requestFieldDataOffset, stringPtr); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | private static int ReadInt(IntPtr buf, int field) | ||
| 197 | { | ||
| 198 | VarEnum vt = (VarEnum) Marshal.ReadInt32(buf, (field * requestFieldSize)); | ||
| 199 | if (vt == VarEnum.VT_EMPTY) | ||
| 200 | { | ||
| 201 | return 0; | ||
| 202 | } | ||
| 203 | else if (vt != VarEnum.VT_I4 && vt != VarEnum.VT_UI4) | ||
| 204 | { | ||
| 205 | throw new InstallerException("Invalid data received from remote MSI function invocation."); | ||
| 206 | } | ||
| 207 | return Marshal.ReadInt32(buf, (field * requestFieldSize) + requestFieldDataOffset); | ||
| 208 | } | ||
| 209 | |||
| 210 | private static void ReadString(IntPtr buf, int field, StringBuilder szBuf, ref uint cchBuf) | ||
| 211 | { | ||
| 212 | VarEnum vt = (VarEnum) Marshal.ReadInt32(buf, (field * requestFieldSize)); | ||
| 213 | if (vt == VarEnum.VT_NULL) | ||
| 214 | { | ||
| 215 | szBuf.Remove(0, szBuf.Length); | ||
| 216 | return; | ||
| 217 | } | ||
| 218 | else if (vt != VarEnum.VT_LPWSTR) | ||
| 219 | { | ||
| 220 | throw new InstallerException("Invalid data received from remote MSI function invocation."); | ||
| 221 | } | ||
| 222 | |||
| 223 | szBuf.Remove(0, szBuf.Length); | ||
| 224 | IntPtr strPtr = Marshal.ReadIntPtr(buf, (field * requestFieldSize) + requestFieldDataOffset); | ||
| 225 | string str = Marshal.PtrToStringUni(strPtr); | ||
| 226 | if (str != null) | ||
| 227 | { | ||
| 228 | szBuf.Append(str); | ||
| 229 | } | ||
| 230 | cchBuf = (uint) szBuf.Length; | ||
| 231 | } | ||
| 232 | |||
| 233 | private static void FreeString(IntPtr buf, int field) | ||
| 234 | { | ||
| 235 | IntPtr stringPtr = Marshal.ReadIntPtr(buf, (field * requestFieldSize) + requestFieldDataOffset); | ||
| 236 | if (stringPtr != IntPtr.Zero) | ||
| 237 | { | ||
| 238 | Marshal.FreeHGlobal(stringPtr); | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | private static void ReadStream(IntPtr buf, int field, byte[] sBuf, int count) | ||
| 243 | { | ||
| 244 | VarEnum vt = (VarEnum) Marshal.ReadInt32(buf, (field * requestFieldSize)); | ||
| 245 | if (vt != VarEnum.VT_STREAM) | ||
| 246 | { | ||
| 247 | throw new InstallerException("Invalid data received from remote MSI function invocation."); | ||
| 248 | } | ||
| 249 | |||
| 250 | IntPtr sPtr = Marshal.ReadIntPtr(buf, (field * requestFieldSize) + requestFieldDataOffset); | ||
| 251 | Marshal.Copy(sPtr, sBuf, 0, count); | ||
| 252 | } | ||
| 253 | |||
| 254 | private static uint MsiFunc_III(RemoteMsiFunctionId id, int in1, int in2, int in3) | ||
| 255 | { | ||
| 256 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 257 | { | ||
| 258 | ClearData(requestBuf); | ||
| 259 | WriteInt(requestBuf, 0, in1); | ||
| 260 | WriteInt(requestBuf, 1, in2); | ||
| 261 | WriteInt(requestBuf, 2, in3); | ||
| 262 | IntPtr resp; | ||
| 263 | remotingDelegate(id, requestBuf, out resp); | ||
| 264 | return unchecked ((uint) ReadInt(resp, 0)); | ||
| 265 | } | ||
| 266 | } | ||
| 267 | |||
| 268 | private static uint MsiFunc_IIS(RemoteMsiFunctionId id, int in1, int in2, string in3) | ||
| 269 | { | ||
| 270 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 271 | { | ||
| 272 | ClearData(requestBuf); | ||
| 273 | WriteInt(requestBuf, 0, in1); | ||
| 274 | WriteInt(requestBuf, 1, in2); | ||
| 275 | WriteString(requestBuf, 2, in3); | ||
| 276 | IntPtr resp; | ||
| 277 | remotingDelegate(id, requestBuf, out resp); | ||
| 278 | FreeString(requestBuf, 2); | ||
| 279 | return unchecked ((uint) ReadInt(resp, 0)); | ||
| 280 | } | ||
| 281 | } | ||
| 282 | |||
| 283 | private static uint MsiFunc_ISI(RemoteMsiFunctionId id, int in1, string in2, int in3) | ||
| 284 | { | ||
| 285 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 286 | { | ||
| 287 | ClearData(requestBuf); | ||
| 288 | WriteInt(requestBuf, 0, in1); | ||
| 289 | WriteString(requestBuf, 1, in2); | ||
| 290 | WriteInt(requestBuf, 2, in3); | ||
| 291 | IntPtr resp; | ||
| 292 | remotingDelegate(id, requestBuf, out resp); | ||
| 293 | FreeString(requestBuf, 2); | ||
| 294 | return unchecked ((uint) ReadInt(resp, 0)); | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | private static uint MsiFunc_ISS(RemoteMsiFunctionId id, int in1, string in2, string in3) | ||
| 299 | { | ||
| 300 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 301 | { | ||
| 302 | ClearData(requestBuf); | ||
| 303 | WriteInt(requestBuf, 0, in1); | ||
| 304 | WriteString(requestBuf, 1, in2); | ||
| 305 | WriteString(requestBuf, 2, in3); | ||
| 306 | IntPtr resp; | ||
| 307 | remotingDelegate(id, requestBuf, out resp); | ||
| 308 | FreeString(requestBuf, 1); | ||
| 309 | FreeString(requestBuf, 2); | ||
| 310 | return unchecked ((uint) ReadInt(resp, 0)); | ||
| 311 | } | ||
| 312 | } | ||
| 313 | |||
| 314 | private static uint MsiFunc_II_I(RemoteMsiFunctionId id, int in1, int in2, out int out1) | ||
| 315 | { | ||
| 316 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 317 | { | ||
| 318 | ClearData(requestBuf); | ||
| 319 | WriteInt(requestBuf, 0, in1); | ||
| 320 | WriteInt(requestBuf, 1, in2); | ||
| 321 | IntPtr resp; | ||
| 322 | remotingDelegate(id, requestBuf, out resp); | ||
| 323 | uint ret = unchecked ((uint) ReadInt(resp, 0)); | ||
| 324 | out1 = ReadInt(resp, 1); | ||
| 325 | return ret; | ||
| 326 | } | ||
| 327 | } | ||
| 328 | |||
| 329 | private static uint MsiFunc_ISII_I(RemoteMsiFunctionId id, int in1, string in2, int in3, int in4, out int out1) | ||
| 330 | { | ||
| 331 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 332 | { | ||
| 333 | ClearData(requestBuf); | ||
| 334 | WriteInt(requestBuf, 0, in1); | ||
| 335 | WriteString(requestBuf, 1, in2); | ||
| 336 | WriteInt(requestBuf, 2, in3); | ||
| 337 | WriteInt(requestBuf, 3, in4); | ||
| 338 | IntPtr resp; | ||
| 339 | remotingDelegate(id, requestBuf, out resp); | ||
| 340 | FreeString(requestBuf, 1); | ||
| 341 | uint ret = unchecked ((uint) ReadInt(resp, 0)); | ||
| 342 | out1 = ReadInt(resp, 1); | ||
| 343 | return ret; | ||
| 344 | } | ||
| 345 | } | ||
| 346 | |||
| 347 | private static uint MsiFunc_IS_II(RemoteMsiFunctionId id, int in1, string in2, out int out1, out int out2) | ||
| 348 | { | ||
| 349 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 350 | { | ||
| 351 | ClearData(requestBuf); | ||
| 352 | WriteInt(requestBuf, 0, in1); | ||
| 353 | WriteString(requestBuf, 1, in2); | ||
| 354 | IntPtr resp; | ||
| 355 | remotingDelegate(id, requestBuf, out resp); | ||
| 356 | FreeString(requestBuf, 1); | ||
| 357 | uint ret = unchecked ((uint) ReadInt(resp, 0)); | ||
| 358 | out1 = ReadInt(resp, 1); | ||
| 359 | out2 = ReadInt(resp, 2); | ||
| 360 | return ret; | ||
| 361 | } | ||
| 362 | } | ||
| 363 | |||
| 364 | private static uint MsiFunc_II_S(RemoteMsiFunctionId id, int in1, int in2, StringBuilder out1, ref uint cchOut1) | ||
| 365 | { | ||
| 366 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 367 | { | ||
| 368 | ClearData(requestBuf); | ||
| 369 | WriteInt(requestBuf, 0, in1); | ||
| 370 | WriteInt(requestBuf, 1, in2); | ||
| 371 | IntPtr resp; | ||
| 372 | remotingDelegate(id, requestBuf, out resp); | ||
| 373 | uint ret = unchecked ((uint) ReadInt(resp, 0)); | ||
| 374 | if (ret == 0) ReadString(resp, 1, out1, ref cchOut1); | ||
| 375 | return ret; | ||
| 376 | } | ||
| 377 | } | ||
| 378 | |||
| 379 | private static uint MsiFunc_IS_S(RemoteMsiFunctionId id, int in1, string in2, StringBuilder out1, ref uint cchOut1) | ||
| 380 | { | ||
| 381 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 382 | { | ||
| 383 | ClearData(requestBuf); | ||
| 384 | WriteInt(requestBuf, 0, in1); | ||
| 385 | WriteString(requestBuf, 1, in2); | ||
| 386 | IntPtr resp; | ||
| 387 | remotingDelegate(id, requestBuf, out resp); | ||
| 388 | FreeString(requestBuf, 1); | ||
| 389 | uint ret = unchecked ((uint) ReadInt(resp, 0)); | ||
| 390 | if (ret == 0) ReadString(resp, 1, out1, ref cchOut1); | ||
| 391 | return ret; | ||
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | private static uint MsiFunc_ISII_SII(RemoteMsiFunctionId id, int in1, string in2, int in3, int in4, StringBuilder out1, ref uint cchOut1, out int out2, out int out3) | ||
| 396 | { | ||
| 397 | lock (RemotableNativeMethods.remotingDelegate) | ||
| 398 | { | ||
| 399 | ClearData(requestBuf); | ||
| 400 | WriteInt(requestBuf, 0, in1); | ||
| 401 | WriteString(requestBuf, 1, in2); | ||
| 402 | WriteInt(requestBuf, 2, in3); | ||
| 403 | WriteInt(requestBuf, 3, in4); | ||
| 404 | IntPtr resp; | ||
| 405 | remotingDelegate(id, requestBuf, out resp); | ||
| 406 | FreeString(requestBuf, 1); | ||
| 407 | uint ret = unchecked ((uint) ReadInt(resp, 0)); | ||
| 408 | if (ret == 0) ReadString(resp, 1, out1, ref cchOut1); | ||
| 409 | out2 = ReadInt(resp, 2); | ||
| 410 | out3 = ReadInt(resp, 3); | ||
| 411 | return ret; | ||
| 412 | } | ||
| 413 | } | ||
| 414 | |||
| 415 | internal static int MsiProcessMessage(int hInstall, uint eMessageType, int hRecord) | ||
| 416 | { | ||
| 417 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 418 | { | ||
| 419 | return NativeMethods.MsiProcessMessage(hInstall, eMessageType, hRecord); | ||
| 420 | } | ||
| 421 | else lock (remotingDelegate) | ||
| 422 | { | ||
| 423 | // I don't understand why, but this particular function doesn't work | ||
| 424 | // when using the static requestBuf -- some data doesn't make it through. | ||
| 425 | // But it works when a fresh buffer is allocated here every call. | ||
| 426 | IntPtr buf = Marshal.AllocHGlobal( | ||
| 427 | requestFieldSize * MAX_REQUEST_FIELDS); | ||
| 428 | ClearData(buf); | ||
| 429 | WriteInt(buf, 0, RemotableNativeMethods.GetRemoteHandle(hInstall)); | ||
| 430 | WriteInt(buf, 1, unchecked ((int) eMessageType)); | ||
| 431 | WriteInt(buf, 2, RemotableNativeMethods.GetRemoteHandle(hRecord)); | ||
| 432 | IntPtr resp; | ||
| 433 | remotingDelegate(RemoteMsiFunctionId.MsiProcessMessage, buf, out resp); | ||
| 434 | Marshal.FreeHGlobal(buf); | ||
| 435 | return ReadInt(resp, 0); | ||
| 436 | } | ||
| 437 | } | ||
| 438 | |||
| 439 | internal static uint MsiCloseHandle(int hAny) | ||
| 440 | { | ||
| 441 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hAny)) | ||
| 442 | return NativeMethods.MsiCloseHandle(hAny); | ||
| 443 | else | ||
| 444 | return RemotableNativeMethods.MsiFunc_III( | ||
| 445 | RemoteMsiFunctionId.MsiCloseHandle, RemotableNativeMethods.GetRemoteHandle(hAny), 0, 0); | ||
| 446 | } | ||
| 447 | |||
| 448 | internal static uint MsiGetProperty(int hInstall, string szName, StringBuilder szValueBuf, ref uint cchValueBuf) | ||
| 449 | { | ||
| 450 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 451 | return NativeMethods.MsiGetProperty(hInstall, szName, szValueBuf, ref cchValueBuf); | ||
| 452 | else | ||
| 453 | { | ||
| 454 | return RemotableNativeMethods.MsiFunc_IS_S( | ||
| 455 | RemoteMsiFunctionId.MsiGetProperty, | ||
| 456 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 457 | szName, | ||
| 458 | szValueBuf, | ||
| 459 | ref cchValueBuf); | ||
| 460 | } | ||
| 461 | } | ||
| 462 | |||
| 463 | internal static uint MsiSetProperty(int hInstall, string szName, string szValue) | ||
| 464 | { | ||
| 465 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 466 | return NativeMethods.MsiSetProperty(hInstall, szName, szValue); | ||
| 467 | else | ||
| 468 | { | ||
| 469 | return RemotableNativeMethods.MsiFunc_ISS( | ||
| 470 | RemoteMsiFunctionId.MsiSetProperty, | ||
| 471 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 472 | szName, | ||
| 473 | szValue); | ||
| 474 | } | ||
| 475 | } | ||
| 476 | |||
| 477 | internal static int MsiCreateRecord(uint cParams, int hAny) | ||
| 478 | { | ||
| 479 | // When remoting is enabled, we might need to create either a local or | ||
| 480 | // remote record, depending on the handle it is to have an affinity with. | ||
| 481 | // If no affinity handle is specified, create a remote record (the 99% case). | ||
| 482 | if (!RemotingEnabled || | ||
| 483 | (hAny != 0 && !RemotableNativeMethods.IsRemoteHandle(hAny))) | ||
| 484 | { | ||
| 485 | return NativeMethods.MsiCreateRecord(cParams); | ||
| 486 | } | ||
| 487 | else | ||
| 488 | { | ||
| 489 | int hRecord = unchecked((int)RemotableNativeMethods.MsiFunc_III( | ||
| 490 | RemoteMsiFunctionId.MsiCreateRecord, (int) cParams, 0, 0)); | ||
| 491 | return RemotableNativeMethods.MakeRemoteHandle(hRecord); | ||
| 492 | } | ||
| 493 | } | ||
| 494 | |||
| 495 | internal static uint MsiRecordGetFieldCount(int hRecord) | ||
| 496 | { | ||
| 497 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 498 | return NativeMethods.MsiRecordGetFieldCount(hRecord); | ||
| 499 | else | ||
| 500 | { | ||
| 501 | return RemotableNativeMethods.MsiFunc_III( | ||
| 502 | RemoteMsiFunctionId.MsiRecordGetFieldCount, | ||
| 503 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 504 | 0, | ||
| 505 | 0); | ||
| 506 | } | ||
| 507 | } | ||
| 508 | |||
| 509 | internal static int MsiRecordGetInteger(int hRecord, uint iField) | ||
| 510 | { | ||
| 511 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 512 | return NativeMethods.MsiRecordGetInteger(hRecord, iField); | ||
| 513 | else | ||
| 514 | { | ||
| 515 | return unchecked ((int) RemotableNativeMethods.MsiFunc_III( | ||
| 516 | RemoteMsiFunctionId.MsiRecordGetInteger, | ||
| 517 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 518 | (int) iField, | ||
| 519 | 0)); | ||
| 520 | } | ||
| 521 | } | ||
| 522 | |||
| 523 | internal static uint MsiRecordGetString(int hRecord, uint iField, StringBuilder szValueBuf, ref uint cchValueBuf) | ||
| 524 | { | ||
| 525 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 526 | { | ||
| 527 | return NativeMethods.MsiRecordGetString(hRecord, iField, szValueBuf, ref cchValueBuf); | ||
| 528 | } | ||
| 529 | else | ||
| 530 | { | ||
| 531 | return RemotableNativeMethods.MsiFunc_II_S( | ||
| 532 | RemoteMsiFunctionId.MsiRecordGetString, | ||
| 533 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 534 | (int) iField, | ||
| 535 | szValueBuf, | ||
| 536 | ref cchValueBuf); | ||
| 537 | } | ||
| 538 | } | ||
| 539 | |||
| 540 | internal static uint MsiRecordSetInteger(int hRecord, uint iField, int iValue) | ||
| 541 | { | ||
| 542 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 543 | return NativeMethods.MsiRecordSetInteger(hRecord, iField, iValue); | ||
| 544 | else | ||
| 545 | { | ||
| 546 | return RemotableNativeMethods.MsiFunc_III( | ||
| 547 | RemoteMsiFunctionId.MsiRecordSetInteger, | ||
| 548 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 549 | (int) iField, | ||
| 550 | iValue); | ||
| 551 | } | ||
| 552 | } | ||
| 553 | |||
| 554 | internal static uint MsiRecordSetString(int hRecord, uint iField, string szValue) | ||
| 555 | { | ||
| 556 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 557 | return NativeMethods.MsiRecordSetString(hRecord, iField, szValue); | ||
| 558 | else | ||
| 559 | { | ||
| 560 | return RemotableNativeMethods.MsiFunc_IIS( | ||
| 561 | RemoteMsiFunctionId.MsiRecordSetString, | ||
| 562 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 563 | (int) iField, | ||
| 564 | szValue); | ||
| 565 | } | ||
| 566 | } | ||
| 567 | |||
| 568 | internal static int MsiGetActiveDatabase(int hInstall) | ||
| 569 | { | ||
| 570 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 571 | return NativeMethods.MsiGetActiveDatabase(hInstall); | ||
| 572 | else | ||
| 573 | { | ||
| 574 | int hDatabase = (int)RemotableNativeMethods.MsiFunc_III( | ||
| 575 | RemoteMsiFunctionId.MsiGetActiveDatabase, | ||
| 576 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 577 | 0, | ||
| 578 | 0); | ||
| 579 | return RemotableNativeMethods.MakeRemoteHandle(hDatabase); | ||
| 580 | } | ||
| 581 | } | ||
| 582 | |||
| 583 | internal static uint MsiDatabaseOpenView(int hDatabase, string szQuery, out int hView) | ||
| 584 | { | ||
| 585 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hDatabase)) | ||
| 586 | return NativeMethods.MsiDatabaseOpenView(hDatabase, szQuery, out hView); | ||
| 587 | else | ||
| 588 | { | ||
| 589 | uint err = RemotableNativeMethods.MsiFunc_ISII_I( | ||
| 590 | RemoteMsiFunctionId.MsiDatabaseOpenView, | ||
| 591 | RemotableNativeMethods.GetRemoteHandle(hDatabase), | ||
| 592 | szQuery, | ||
| 593 | 0, | ||
| 594 | 0, | ||
| 595 | out hView); | ||
| 596 | hView = RemotableNativeMethods.MakeRemoteHandle(hView); | ||
| 597 | return err; | ||
| 598 | } | ||
| 599 | } | ||
| 600 | |||
| 601 | internal static uint MsiViewExecute(int hView, int hRecord) | ||
| 602 | { | ||
| 603 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hView)) | ||
| 604 | return NativeMethods.MsiViewExecute(hView, hRecord); | ||
| 605 | else | ||
| 606 | { | ||
| 607 | return RemotableNativeMethods.MsiFunc_III( | ||
| 608 | RemoteMsiFunctionId.MsiViewExecute, | ||
| 609 | RemotableNativeMethods.GetRemoteHandle(hView), | ||
| 610 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 611 | 0); | ||
| 612 | } | ||
| 613 | } | ||
| 614 | |||
| 615 | internal static uint MsiViewFetch(int hView, out int hRecord) | ||
| 616 | { | ||
| 617 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hView)) | ||
| 618 | return NativeMethods.MsiViewFetch(hView, out hRecord); | ||
| 619 | else | ||
| 620 | { | ||
| 621 | uint err = RemotableNativeMethods.MsiFunc_II_I( | ||
| 622 | RemoteMsiFunctionId.MsiViewFetch, | ||
| 623 | RemotableNativeMethods.GetRemoteHandle(hView), | ||
| 624 | 0, | ||
| 625 | out hRecord); | ||
| 626 | hRecord = RemotableNativeMethods.MakeRemoteHandle(hRecord); | ||
| 627 | return err; | ||
| 628 | } | ||
| 629 | } | ||
| 630 | |||
| 631 | internal static uint MsiViewModify(int hView, int iModifyMode, int hRecord) | ||
| 632 | { | ||
| 633 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hView)) | ||
| 634 | return NativeMethods.MsiViewModify(hView, iModifyMode, hRecord); | ||
| 635 | else | ||
| 636 | { | ||
| 637 | return RemotableNativeMethods.MsiFunc_III( | ||
| 638 | RemoteMsiFunctionId.MsiViewModify, | ||
| 639 | RemotableNativeMethods.GetRemoteHandle(hView), | ||
| 640 | iModifyMode, | ||
| 641 | RemotableNativeMethods.GetRemoteHandle(hRecord)); | ||
| 642 | } | ||
| 643 | } | ||
| 644 | |||
| 645 | internal static int MsiViewGetError(int hView, StringBuilder szColumnNameBuffer, ref uint cchBuf) | ||
| 646 | { | ||
| 647 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hView)) | ||
| 648 | return NativeMethods.MsiViewGetError(hView, szColumnNameBuffer, ref cchBuf); | ||
| 649 | else | ||
| 650 | { | ||
| 651 | return unchecked ((int) RemotableNativeMethods.MsiFunc_II_S( | ||
| 652 | RemoteMsiFunctionId.MsiViewGetError, | ||
| 653 | RemotableNativeMethods.GetRemoteHandle(hView), | ||
| 654 | 0, | ||
| 655 | szColumnNameBuffer, | ||
| 656 | ref cchBuf)); | ||
| 657 | } | ||
| 658 | } | ||
| 659 | |||
| 660 | internal static uint MsiViewGetColumnInfo(int hView, uint eColumnInfo, out int hRecord) | ||
| 661 | { | ||
| 662 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hView)) | ||
| 663 | return NativeMethods.MsiViewGetColumnInfo(hView, eColumnInfo, out hRecord); | ||
| 664 | else | ||
| 665 | { | ||
| 666 | uint err = RemotableNativeMethods.MsiFunc_II_I( | ||
| 667 | RemoteMsiFunctionId.MsiViewGetColumnInfo, | ||
| 668 | RemotableNativeMethods.GetRemoteHandle(hView), | ||
| 669 | (int) eColumnInfo, | ||
| 670 | out hRecord); | ||
| 671 | hRecord = RemotableNativeMethods.MakeRemoteHandle(hRecord); | ||
| 672 | return err; | ||
| 673 | } | ||
| 674 | } | ||
| 675 | |||
| 676 | internal static uint MsiFormatRecord(int hInstall, int hRecord, StringBuilder szResultBuf, ref uint cchResultBuf) | ||
| 677 | { | ||
| 678 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 679 | return NativeMethods.MsiFormatRecord(hInstall, hRecord, szResultBuf, ref cchResultBuf); | ||
| 680 | else | ||
| 681 | { | ||
| 682 | return RemotableNativeMethods.MsiFunc_II_S( | ||
| 683 | RemoteMsiFunctionId.MsiFormatRecord, | ||
| 684 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 685 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 686 | szResultBuf, | ||
| 687 | ref cchResultBuf); | ||
| 688 | } | ||
| 689 | } | ||
| 690 | |||
| 691 | internal static uint MsiRecordClearData(int hRecord) | ||
| 692 | { | ||
| 693 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 694 | return NativeMethods.MsiRecordClearData(hRecord); | ||
| 695 | else | ||
| 696 | { | ||
| 697 | return RemotableNativeMethods.MsiFunc_III( | ||
| 698 | RemoteMsiFunctionId.MsiRecordClearData, | ||
| 699 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 700 | 0, | ||
| 701 | 0); | ||
| 702 | } | ||
| 703 | } | ||
| 704 | |||
| 705 | internal static bool MsiRecordIsNull(int hRecord, uint iField) | ||
| 706 | { | ||
| 707 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 708 | return NativeMethods.MsiRecordIsNull(hRecord, iField); | ||
| 709 | else | ||
| 710 | { | ||
| 711 | return 0 != RemotableNativeMethods.MsiFunc_III( | ||
| 712 | RemoteMsiFunctionId.MsiRecordIsNull, | ||
| 713 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 714 | (int) iField, | ||
| 715 | 0); | ||
| 716 | } | ||
| 717 | } | ||
| 718 | |||
| 719 | internal static uint MsiDatabaseGetPrimaryKeys(int hDatabase, string szTableName, out int hRecord) | ||
| 720 | { | ||
| 721 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hDatabase)) | ||
| 722 | return NativeMethods.MsiDatabaseGetPrimaryKeys(hDatabase, szTableName, out hRecord); | ||
| 723 | else | ||
| 724 | { | ||
| 725 | uint err = RemotableNativeMethods.MsiFunc_ISII_I( | ||
| 726 | RemoteMsiFunctionId.MsiDatabaseGetPrimaryKeys, | ||
| 727 | RemotableNativeMethods.GetRemoteHandle(hDatabase), | ||
| 728 | szTableName, | ||
| 729 | 0, | ||
| 730 | 0, | ||
| 731 | out hRecord); | ||
| 732 | hRecord = RemotableNativeMethods.MakeRemoteHandle(hRecord); | ||
| 733 | return err; | ||
| 734 | } | ||
| 735 | } | ||
| 736 | |||
| 737 | internal static uint MsiDatabaseIsTablePersistent(int hDatabase, string szTableName) | ||
| 738 | { | ||
| 739 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hDatabase)) | ||
| 740 | return NativeMethods.MsiDatabaseIsTablePersistent(hDatabase, szTableName); | ||
| 741 | else | ||
| 742 | { | ||
| 743 | return RemotableNativeMethods.MsiFunc_ISI( | ||
| 744 | RemoteMsiFunctionId.MsiDatabaseIsTablePersistent, | ||
| 745 | RemotableNativeMethods.GetRemoteHandle(hDatabase), | ||
| 746 | szTableName, | ||
| 747 | 0); | ||
| 748 | } | ||
| 749 | } | ||
| 750 | |||
| 751 | internal static uint MsiDoAction(int hInstall, string szAction) | ||
| 752 | { | ||
| 753 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 754 | return NativeMethods.MsiDoAction(hInstall, szAction); | ||
| 755 | else | ||
| 756 | { | ||
| 757 | return RemotableNativeMethods.MsiFunc_ISI( | ||
| 758 | RemoteMsiFunctionId.MsiDoAction, | ||
| 759 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 760 | szAction, | ||
| 761 | 0); | ||
| 762 | } | ||
| 763 | } | ||
| 764 | |||
| 765 | internal static uint MsiEnumComponentCosts(int hInstall, string szComponent, uint dwIndex, int iState, StringBuilder lpDriveBuf, ref uint cchDriveBuf, out int iCost, out int iTempCost) | ||
| 766 | { | ||
| 767 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 768 | return NativeMethods.MsiEnumComponentCosts(hInstall, szComponent, dwIndex, iState, lpDriveBuf, ref cchDriveBuf, out iCost, out iTempCost); | ||
| 769 | else | ||
| 770 | { | ||
| 771 | return RemotableNativeMethods.MsiFunc_ISII_SII( | ||
| 772 | RemoteMsiFunctionId.MsiEvaluateCondition, | ||
| 773 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 774 | szComponent, (int) dwIndex, iState, lpDriveBuf, ref cchDriveBuf, out iCost, out iTempCost); | ||
| 775 | } | ||
| 776 | } | ||
| 777 | |||
| 778 | internal static uint MsiEvaluateCondition(int hInstall, string szCondition) | ||
| 779 | { | ||
| 780 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 781 | return NativeMethods.MsiEvaluateCondition(hInstall, szCondition); | ||
| 782 | else | ||
| 783 | { | ||
| 784 | return RemotableNativeMethods.MsiFunc_ISI( | ||
| 785 | RemoteMsiFunctionId.MsiEvaluateCondition, | ||
| 786 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 787 | szCondition, | ||
| 788 | 0); | ||
| 789 | } | ||
| 790 | } | ||
| 791 | |||
| 792 | internal static uint MsiGetComponentState(int hInstall, string szComponent, out int iInstalled, out int iAction) | ||
| 793 | { | ||
| 794 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 795 | return NativeMethods.MsiGetComponentState(hInstall, szComponent, out iInstalled, out iAction); | ||
| 796 | else | ||
| 797 | { | ||
| 798 | return RemotableNativeMethods.MsiFunc_IS_II( | ||
| 799 | RemoteMsiFunctionId.MsiGetComponentState, | ||
| 800 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 801 | szComponent, | ||
| 802 | out iInstalled, | ||
| 803 | out iAction); | ||
| 804 | } | ||
| 805 | } | ||
| 806 | |||
| 807 | internal static uint MsiGetFeatureCost(int hInstall, string szFeature, int iCostTree, int iState, out int iCost) | ||
| 808 | { | ||
| 809 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 810 | return NativeMethods.MsiGetFeatureCost(hInstall, szFeature, iCostTree, iState, out iCost); | ||
| 811 | else | ||
| 812 | { | ||
| 813 | return RemotableNativeMethods.MsiFunc_ISII_I( | ||
| 814 | RemoteMsiFunctionId.MsiGetFeatureCost, | ||
| 815 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 816 | szFeature, | ||
| 817 | iCostTree, | ||
| 818 | iState, | ||
| 819 | out iCost); | ||
| 820 | } | ||
| 821 | } | ||
| 822 | |||
| 823 | internal static uint MsiGetFeatureState(int hInstall, string szFeature, out int iInstalled, out int iAction) | ||
| 824 | { | ||
| 825 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 826 | return NativeMethods.MsiGetFeatureState(hInstall, szFeature, out iInstalled, out iAction); | ||
| 827 | else | ||
| 828 | { | ||
| 829 | return RemotableNativeMethods.MsiFunc_IS_II( | ||
| 830 | RemoteMsiFunctionId.MsiGetFeatureState, | ||
| 831 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 832 | szFeature, | ||
| 833 | out iInstalled, | ||
| 834 | out iAction); | ||
| 835 | } | ||
| 836 | } | ||
| 837 | |||
| 838 | internal static uint MsiGetFeatureValidStates(int hInstall, string szFeature, out uint dwInstalledState) | ||
| 839 | { | ||
| 840 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 841 | return NativeMethods.MsiGetFeatureValidStates(hInstall, szFeature, out dwInstalledState); | ||
| 842 | else | ||
| 843 | { | ||
| 844 | int iTemp; | ||
| 845 | uint ret = RemotableNativeMethods.MsiFunc_ISII_I( | ||
| 846 | RemoteMsiFunctionId.MsiGetFeatureValidStates, | ||
| 847 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 848 | szFeature, | ||
| 849 | 0, | ||
| 850 | 0, | ||
| 851 | out iTemp); | ||
| 852 | dwInstalledState = (uint) iTemp; | ||
| 853 | return ret; | ||
| 854 | } | ||
| 855 | } | ||
| 856 | |||
| 857 | internal static int MsiGetLanguage(int hInstall) | ||
| 858 | { | ||
| 859 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 860 | return NativeMethods.MsiGetLanguage(hInstall); | ||
| 861 | else | ||
| 862 | { | ||
| 863 | return unchecked((int)RemotableNativeMethods.MsiFunc_III( | ||
| 864 | RemoteMsiFunctionId.MsiGetLanguage, | ||
| 865 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 866 | 0, | ||
| 867 | 0)); | ||
| 868 | } | ||
| 869 | } | ||
| 870 | |||
| 871 | internal static int MsiGetLastErrorRecord(int hAny) | ||
| 872 | { | ||
| 873 | // When remoting is enabled, we might need to create either a local or | ||
| 874 | // remote record, depending on the handle it is to have an affinity with. | ||
| 875 | // If no affinity handle is specified, create a remote record (the 99% case). | ||
| 876 | if (!RemotingEnabled || | ||
| 877 | (hAny != 0 && !RemotableNativeMethods.IsRemoteHandle(hAny))) | ||
| 878 | { | ||
| 879 | return NativeMethods.MsiGetLastErrorRecord(); | ||
| 880 | } | ||
| 881 | else | ||
| 882 | { | ||
| 883 | int hRecord = unchecked((int) RemotableNativeMethods.MsiFunc_III( | ||
| 884 | RemoteMsiFunctionId.MsiGetLastErrorRecord, 0, 0, 0)); | ||
| 885 | return RemotableNativeMethods.MakeRemoteHandle(hRecord); | ||
| 886 | } | ||
| 887 | } | ||
| 888 | |||
| 889 | internal static bool MsiGetMode(int hInstall, uint iRunMode) | ||
| 890 | { | ||
| 891 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 892 | return NativeMethods.MsiGetMode(hInstall, iRunMode); | ||
| 893 | else | ||
| 894 | { | ||
| 895 | return 0 != RemotableNativeMethods.MsiFunc_III( | ||
| 896 | RemoteMsiFunctionId.MsiGetMode, | ||
| 897 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 898 | (int) iRunMode, | ||
| 899 | 0); | ||
| 900 | } | ||
| 901 | } | ||
| 902 | |||
| 903 | internal static uint MsiGetSourcePath(int hInstall, string szFolder, StringBuilder szPathBuf, ref uint cchPathBuf) | ||
| 904 | { | ||
| 905 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 906 | return NativeMethods.MsiGetSourcePath(hInstall, szFolder, szPathBuf, ref cchPathBuf); | ||
| 907 | else | ||
| 908 | { | ||
| 909 | return RemotableNativeMethods.MsiFunc_IS_S( | ||
| 910 | RemoteMsiFunctionId.MsiGetSourcePath, | ||
| 911 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 912 | szFolder, | ||
| 913 | szPathBuf, | ||
| 914 | ref cchPathBuf); | ||
| 915 | } | ||
| 916 | } | ||
| 917 | |||
| 918 | internal static uint MsiGetSummaryInformation(int hDatabase, string szDatabasePath, uint uiUpdateCount, out int hSummaryInfo) | ||
| 919 | { | ||
| 920 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hDatabase)) | ||
| 921 | return NativeMethods.MsiGetSummaryInformation(hDatabase, szDatabasePath, uiUpdateCount, out hSummaryInfo); | ||
| 922 | else | ||
| 923 | { | ||
| 924 | uint err = RemotableNativeMethods.MsiFunc_ISII_I( | ||
| 925 | RemoteMsiFunctionId.MsiGetSummaryInformation, | ||
| 926 | RemotableNativeMethods.GetRemoteHandle(hDatabase), | ||
| 927 | szDatabasePath, | ||
| 928 | (int)uiUpdateCount, | ||
| 929 | 0, | ||
| 930 | out hSummaryInfo); | ||
| 931 | hSummaryInfo = RemotableNativeMethods.MakeRemoteHandle(hSummaryInfo); | ||
| 932 | return err; | ||
| 933 | } | ||
| 934 | } | ||
| 935 | |||
| 936 | internal static uint MsiGetTargetPath(int hInstall, string szFolder, StringBuilder szPathBuf, ref uint cchPathBuf) | ||
| 937 | { | ||
| 938 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 939 | return NativeMethods.MsiGetTargetPath(hInstall, szFolder, szPathBuf, ref cchPathBuf); | ||
| 940 | else | ||
| 941 | { | ||
| 942 | return RemotableNativeMethods.MsiFunc_IS_S( | ||
| 943 | RemoteMsiFunctionId.MsiGetTargetPath, | ||
| 944 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 945 | szFolder, | ||
| 946 | szPathBuf, | ||
| 947 | ref cchPathBuf); | ||
| 948 | } | ||
| 949 | } | ||
| 950 | |||
| 951 | internal static uint MsiRecordDataSize(int hRecord, uint iField) | ||
| 952 | { | ||
| 953 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 954 | return NativeMethods.MsiRecordDataSize(hRecord, iField); | ||
| 955 | else | ||
| 956 | { | ||
| 957 | return RemotableNativeMethods.MsiFunc_III( | ||
| 958 | RemoteMsiFunctionId.MsiRecordDataSize, | ||
| 959 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 960 | (int) iField, 0); | ||
| 961 | } | ||
| 962 | } | ||
| 963 | |||
| 964 | internal static uint MsiRecordReadStream(int hRecord, uint iField, byte[] szDataBuf, ref uint cbDataBuf) | ||
| 965 | { | ||
| 966 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 967 | { | ||
| 968 | return NativeMethods.MsiRecordReadStream(hRecord, iField, szDataBuf, ref cbDataBuf); | ||
| 969 | } | ||
| 970 | else lock (RemotableNativeMethods.remotingDelegate) | ||
| 971 | { | ||
| 972 | ClearData(requestBuf); | ||
| 973 | unchecked | ||
| 974 | { | ||
| 975 | WriteInt(requestBuf, 0, RemotableNativeMethods.GetRemoteHandle(hRecord)); | ||
| 976 | WriteInt(requestBuf, 1, (int) iField); | ||
| 977 | WriteInt(requestBuf, 2, (int) cbDataBuf); | ||
| 978 | IntPtr resp; | ||
| 979 | remotingDelegate(RemoteMsiFunctionId.MsiRecordReadStream, requestBuf, out resp); | ||
| 980 | uint ret = (uint) ReadInt(resp, 0); | ||
| 981 | if (ret == 0) | ||
| 982 | { | ||
| 983 | cbDataBuf = (uint) ReadInt(resp, 2); | ||
| 984 | if (cbDataBuf > 0) | ||
| 985 | { | ||
| 986 | RemotableNativeMethods.ReadStream(resp, 1, szDataBuf, (int) cbDataBuf); | ||
| 987 | } | ||
| 988 | } | ||
| 989 | return ret; | ||
| 990 | } | ||
| 991 | } | ||
| 992 | } | ||
| 993 | |||
| 994 | internal static uint MsiRecordSetStream(int hRecord, uint iField, string szFilePath) | ||
| 995 | { | ||
| 996 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hRecord)) | ||
| 997 | return NativeMethods.MsiRecordSetStream(hRecord, iField, szFilePath); | ||
| 998 | else | ||
| 999 | { | ||
| 1000 | return RemotableNativeMethods.MsiFunc_IIS( | ||
| 1001 | RemoteMsiFunctionId.MsiRecordSetStream, | ||
| 1002 | RemotableNativeMethods.GetRemoteHandle(hRecord), | ||
| 1003 | (int) iField, | ||
| 1004 | szFilePath); | ||
| 1005 | } | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | internal static uint MsiSequence(int hInstall, string szTable, int iSequenceMode) | ||
| 1009 | { | ||
| 1010 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 1011 | return NativeMethods.MsiSequence(hInstall, szTable, iSequenceMode); | ||
| 1012 | else | ||
| 1013 | { | ||
| 1014 | return RemotableNativeMethods.MsiFunc_ISI( | ||
| 1015 | RemoteMsiFunctionId.MsiSequence, | ||
| 1016 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 1017 | szTable, | ||
| 1018 | iSequenceMode); | ||
| 1019 | } | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | internal static uint MsiSetComponentState(int hInstall, string szComponent, int iState) | ||
| 1023 | { | ||
| 1024 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 1025 | return NativeMethods.MsiSetComponentState(hInstall, szComponent, iState); | ||
| 1026 | else | ||
| 1027 | { | ||
| 1028 | return RemotableNativeMethods.MsiFunc_ISI( | ||
| 1029 | RemoteMsiFunctionId.MsiSetComponentState, | ||
| 1030 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 1031 | szComponent, | ||
| 1032 | iState); | ||
| 1033 | } | ||
| 1034 | } | ||
| 1035 | |||
| 1036 | internal static uint MsiSetFeatureAttributes(int hInstall, string szFeature, uint dwAttributes) | ||
| 1037 | { | ||
| 1038 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 1039 | return NativeMethods.MsiSetFeatureAttributes(hInstall, szFeature, dwAttributes); | ||
| 1040 | else | ||
| 1041 | { | ||
| 1042 | return RemotableNativeMethods.MsiFunc_ISI( | ||
| 1043 | RemoteMsiFunctionId.MsiSetFeatureAttributes, | ||
| 1044 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 1045 | szFeature, | ||
| 1046 | (int) dwAttributes); | ||
| 1047 | } | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | internal static uint MsiSetFeatureState(int hInstall, string szFeature, int iState) | ||
| 1051 | { | ||
| 1052 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 1053 | return NativeMethods.MsiSetFeatureState(hInstall, szFeature, iState); | ||
| 1054 | else | ||
| 1055 | { | ||
| 1056 | return RemotableNativeMethods.MsiFunc_ISI( | ||
| 1057 | RemoteMsiFunctionId.MsiSetFeatureState, | ||
| 1058 | RemotableNativeMethods.GetRemoteHandle(hInstall), szFeature, iState); | ||
| 1059 | } | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | internal static uint MsiSetInstallLevel(int hInstall, int iInstallLevel) | ||
| 1063 | { | ||
| 1064 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 1065 | return NativeMethods.MsiSetInstallLevel(hInstall, iInstallLevel); | ||
| 1066 | else | ||
| 1067 | { | ||
| 1068 | return RemotableNativeMethods.MsiFunc_III( | ||
| 1069 | RemoteMsiFunctionId.MsiSetInstallLevel, | ||
| 1070 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 1071 | iInstallLevel, | ||
| 1072 | 0); | ||
| 1073 | } | ||
| 1074 | } | ||
| 1075 | |||
| 1076 | internal static uint MsiSetMode(int hInstall, uint iRunMode, bool fState) | ||
| 1077 | { | ||
| 1078 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 1079 | return NativeMethods.MsiSetMode(hInstall, iRunMode, fState); | ||
| 1080 | else | ||
| 1081 | { | ||
| 1082 | return RemotableNativeMethods.MsiFunc_III( | ||
| 1083 | RemoteMsiFunctionId.MsiSetMode, | ||
| 1084 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 1085 | (int) iRunMode, | ||
| 1086 | fState ? 1 : 0); | ||
| 1087 | } | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | internal static uint MsiSetTargetPath(int hInstall, string szFolder, string szFolderPath) | ||
| 1091 | { | ||
| 1092 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 1093 | return NativeMethods.MsiSetTargetPath(hInstall, szFolder, szFolderPath); | ||
| 1094 | else | ||
| 1095 | { | ||
| 1096 | return RemotableNativeMethods.MsiFunc_ISS( | ||
| 1097 | RemoteMsiFunctionId.MsiSetTargetPath, | ||
| 1098 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 1099 | szFolder, | ||
| 1100 | szFolderPath); | ||
| 1101 | } | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | internal static uint MsiSummaryInfoGetProperty(int hSummaryInfo, uint uiProperty, out uint uiDataType, out int iValue, ref long ftValue, StringBuilder szValueBuf, ref uint cchValueBuf) | ||
| 1105 | { | ||
| 1106 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hSummaryInfo)) | ||
| 1107 | { | ||
| 1108 | return NativeMethods.MsiSummaryInfoGetProperty(hSummaryInfo, uiProperty, out uiDataType, out iValue, ref ftValue, szValueBuf, ref cchValueBuf); | ||
| 1109 | } | ||
| 1110 | else lock (RemotableNativeMethods.remotingDelegate) | ||
| 1111 | { | ||
| 1112 | ClearData(requestBuf); | ||
| 1113 | WriteInt(requestBuf, 0, RemotableNativeMethods.GetRemoteHandle(hSummaryInfo)); | ||
| 1114 | WriteInt(requestBuf, 1, (int) uiProperty); | ||
| 1115 | IntPtr resp; | ||
| 1116 | remotingDelegate(RemoteMsiFunctionId.MsiSummaryInfoGetProperty, requestBuf, out resp); | ||
| 1117 | unchecked | ||
| 1118 | { | ||
| 1119 | uint ret = (uint) ReadInt(resp, 0); | ||
| 1120 | if (ret == 0) | ||
| 1121 | { | ||
| 1122 | uiDataType = (uint) ReadInt(resp, 1); | ||
| 1123 | switch ((VarEnum) uiDataType) | ||
| 1124 | { | ||
| 1125 | case VarEnum.VT_I2: | ||
| 1126 | case VarEnum.VT_I4: | ||
| 1127 | iValue = ReadInt(resp, 2); | ||
| 1128 | break; | ||
| 1129 | |||
| 1130 | case VarEnum.VT_FILETIME: | ||
| 1131 | uint ftHigh = (uint) ReadInt(resp, 2); | ||
| 1132 | uint ftLow = (uint) ReadInt(resp, 3); | ||
| 1133 | ftValue = ((long) ftHigh) << 32 | ((long) ftLow); | ||
| 1134 | iValue = 0; | ||
| 1135 | break; | ||
| 1136 | |||
| 1137 | case VarEnum.VT_LPSTR: | ||
| 1138 | ReadString(resp, 2, szValueBuf, ref cchValueBuf); | ||
| 1139 | iValue = 0; | ||
| 1140 | break; | ||
| 1141 | |||
| 1142 | default: | ||
| 1143 | iValue = 0; | ||
| 1144 | break; | ||
| 1145 | } | ||
| 1146 | } | ||
| 1147 | else | ||
| 1148 | { | ||
| 1149 | uiDataType = 0; | ||
| 1150 | iValue = 0; | ||
| 1151 | } | ||
| 1152 | return ret; | ||
| 1153 | } | ||
| 1154 | } | ||
| 1155 | } | ||
| 1156 | |||
| 1157 | internal static uint MsiVerifyDiskSpace(int hInstall) | ||
| 1158 | { | ||
| 1159 | if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall)) | ||
| 1160 | return NativeMethods.MsiVerifyDiskSpace(hInstall); | ||
| 1161 | else | ||
| 1162 | { | ||
| 1163 | return RemotableNativeMethods.MsiFunc_III( | ||
| 1164 | RemoteMsiFunctionId.MsiVerifyDiskSpace, | ||
| 1165 | RemotableNativeMethods.GetRemoteHandle(hInstall), | ||
| 1166 | 0, | ||
| 1167 | 0); | ||
| 1168 | } | ||
| 1169 | } | ||
| 1170 | } | ||
| 1171 | } | ||
