diff options
Diffstat (limited to 'src/WixToolset.Mba.Core/Engine.cs')
-rw-r--r-- | src/WixToolset.Mba.Core/Engine.cs | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/WixToolset.Mba.Core/Engine.cs b/src/WixToolset.Mba.Core/Engine.cs index e07ecd8b..aed420d5 100644 --- a/src/WixToolset.Mba.Core/Engine.cs +++ b/src/WixToolset.Mba.Core/Engine.cs | |||
@@ -62,7 +62,7 @@ namespace WixToolset.Mba.Core | |||
62 | /// <inheritdoc/> | 62 | /// <inheritdoc/> |
63 | public bool ContainsVariable(string name) | 63 | public bool ContainsVariable(string name) |
64 | { | 64 | { |
65 | int capacity = 0; | 65 | IntPtr capacity = new IntPtr(0); |
66 | int ret = this.engine.GetVariableString(name, IntPtr.Zero, ref capacity); | 66 | int ret = this.engine.GetVariableString(name, IntPtr.Zero, ref capacity); |
67 | return NativeMethods.E_NOTFOUND != ret; | 67 | return NativeMethods.E_NOTFOUND != ret; |
68 | } | 68 | } |
@@ -101,14 +101,15 @@ namespace WixToolset.Mba.Core | |||
101 | /// <inheritdoc/> | 101 | /// <inheritdoc/> |
102 | public string EscapeString(string input) | 102 | public string EscapeString(string input) |
103 | { | 103 | { |
104 | int capacity = InitialBufferSize; | 104 | IntPtr capacity = new IntPtr(InitialBufferSize); |
105 | StringBuilder sb = new StringBuilder(capacity); | 105 | StringBuilder sb = new StringBuilder(capacity.ToInt32()); |
106 | 106 | ||
107 | // Get the size of the buffer. | 107 | // Get the size of the buffer. |
108 | int ret = this.engine.EscapeString(input, sb, ref capacity); | 108 | int ret = this.engine.EscapeString(input, sb, ref capacity); |
109 | if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) | 109 | if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) |
110 | { | 110 | { |
111 | sb.Capacity = ++capacity; // Add one for the null terminator. | 111 | capacity = new IntPtr(capacity.ToInt32() + 1); // Add one for the null terminator. |
112 | sb.Capacity = capacity.ToInt32(); | ||
112 | ret = this.engine.EscapeString(input, sb, ref capacity); | 113 | ret = this.engine.EscapeString(input, sb, ref capacity); |
113 | } | 114 | } |
114 | 115 | ||
@@ -132,14 +133,15 @@ namespace WixToolset.Mba.Core | |||
132 | /// <inheritdoc/> | 133 | /// <inheritdoc/> |
133 | public string FormatString(string format) | 134 | public string FormatString(string format) |
134 | { | 135 | { |
135 | int capacity = InitialBufferSize; | 136 | IntPtr capacity = new IntPtr(InitialBufferSize); |
136 | StringBuilder sb = new StringBuilder(capacity); | 137 | StringBuilder sb = new StringBuilder(capacity.ToInt32()); |
137 | 138 | ||
138 | // Get the size of the buffer. | 139 | // Get the size of the buffer. |
139 | int ret = this.engine.FormatString(format, sb, ref capacity); | 140 | int ret = this.engine.FormatString(format, sb, ref capacity); |
140 | if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) | 141 | if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) |
141 | { | 142 | { |
142 | sb.Capacity = ++capacity; // Add one for the null terminator. | 143 | capacity = new IntPtr(capacity.ToInt32() + 1); // Add one for the null terminator. |
144 | sb.Capacity = capacity.ToInt32(); | ||
143 | ret = this.engine.FormatString(format, sb, ref capacity); | 145 | ret = this.engine.FormatString(format, sb, ref capacity); |
144 | } | 146 | } |
145 | 147 | ||
@@ -343,9 +345,9 @@ namespace WixToolset.Mba.Core | |||
343 | /// <exception cref="Exception">An error occurred getting the variable.</exception> | 345 | /// <exception cref="Exception">An error occurred getting the variable.</exception> |
344 | internal IntPtr getStringVariable(string name, out int length) | 346 | internal IntPtr getStringVariable(string name, out int length) |
345 | { | 347 | { |
346 | int capacity = InitialBufferSize; | 348 | IntPtr capacity = new IntPtr(InitialBufferSize); |
347 | bool success = false; | 349 | bool success = false; |
348 | IntPtr pValue = Marshal.AllocCoTaskMem(capacity * UnicodeEncoding.CharSize); | 350 | IntPtr pValue = Marshal.AllocCoTaskMem(capacity.ToInt32() * UnicodeEncoding.CharSize); |
349 | try | 351 | try |
350 | { | 352 | { |
351 | // Get the size of the buffer. | 353 | // Get the size of the buffer. |
@@ -353,7 +355,7 @@ namespace WixToolset.Mba.Core | |||
353 | if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) | 355 | if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) |
354 | { | 356 | { |
355 | // Don't need to add 1 for the null terminator, the engine already includes that. | 357 | // Don't need to add 1 for the null terminator, the engine already includes that. |
356 | pValue = Marshal.ReAllocCoTaskMem(pValue, capacity * UnicodeEncoding.CharSize); | 358 | pValue = Marshal.ReAllocCoTaskMem(pValue, capacity.ToInt32() * UnicodeEncoding.CharSize); |
357 | ret = this.engine.GetVariableString(name, pValue, ref capacity); | 359 | ret = this.engine.GetVariableString(name, pValue, ref capacity); |
358 | } | 360 | } |
359 | 361 | ||
@@ -363,9 +365,10 @@ namespace WixToolset.Mba.Core | |||
363 | } | 365 | } |
364 | 366 | ||
365 | // The engine only returns the exact length of the string if the buffer was too small, so calculate it ourselves. | 367 | // The engine only returns the exact length of the string if the buffer was too small, so calculate it ourselves. |
366 | for (length = 0; length < capacity; ++length) | 368 | int maxLength = capacity.ToInt32(); |
369 | for (length = 0; length < maxLength; ++length) | ||
367 | { | 370 | { |
368 | if(0 == Marshal.ReadInt16(pValue, length * UnicodeEncoding.CharSize)) | 371 | if (0 == Marshal.ReadInt16(pValue, length * UnicodeEncoding.CharSize)) |
369 | { | 372 | { |
370 | break; | 373 | break; |
371 | } | 374 | } |
@@ -392,9 +395,9 @@ namespace WixToolset.Mba.Core | |||
392 | /// <exception cref="Exception">An error occurred getting the variable.</exception> | 395 | /// <exception cref="Exception">An error occurred getting the variable.</exception> |
393 | internal IntPtr getVersionVariable(string name, out int length) | 396 | internal IntPtr getVersionVariable(string name, out int length) |
394 | { | 397 | { |
395 | int capacity = InitialBufferSize; | 398 | IntPtr capacity = new IntPtr(InitialBufferSize); |
396 | bool success = false; | 399 | bool success = false; |
397 | IntPtr pValue = Marshal.AllocCoTaskMem(capacity * UnicodeEncoding.CharSize); | 400 | IntPtr pValue = Marshal.AllocCoTaskMem(capacity.ToInt32() * UnicodeEncoding.CharSize); |
398 | try | 401 | try |
399 | { | 402 | { |
400 | // Get the size of the buffer. | 403 | // Get the size of the buffer. |
@@ -402,7 +405,7 @@ namespace WixToolset.Mba.Core | |||
402 | if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) | 405 | if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) |
403 | { | 406 | { |
404 | // Don't need to add 1 for the null terminator, the engine already includes that. | 407 | // Don't need to add 1 for the null terminator, the engine already includes that. |
405 | pValue = Marshal.ReAllocCoTaskMem(pValue, capacity * UnicodeEncoding.CharSize); | 408 | pValue = Marshal.ReAllocCoTaskMem(pValue, capacity.ToInt32() * UnicodeEncoding.CharSize); |
406 | ret = this.engine.GetVariableVersion(name, pValue, ref capacity); | 409 | ret = this.engine.GetVariableVersion(name, pValue, ref capacity); |
407 | } | 410 | } |
408 | 411 | ||
@@ -412,7 +415,8 @@ namespace WixToolset.Mba.Core | |||
412 | } | 415 | } |
413 | 416 | ||
414 | // The engine only returns the exact length of the string if the buffer was too small, so calculate it ourselves. | 417 | // The engine only returns the exact length of the string if the buffer was too small, so calculate it ourselves. |
415 | for (length = 0; length < capacity; ++length) | 418 | int maxLength = capacity.ToInt32(); |
419 | for (length = 0; length < maxLength; ++length) | ||
416 | { | 420 | { |
417 | if (0 == Marshal.ReadInt16(pValue, length * UnicodeEncoding.CharSize)) | 421 | if (0 == Marshal.ReadInt16(pValue, length * UnicodeEncoding.CharSize)) |
418 | { | 422 | { |