From cca953eb5fc5e8a40a183bc4f4adb48823f8683f Mon Sep 17 00:00:00 2001 From: David Hall Date: Tue, 8 Oct 2019 13:29:30 -0600 Subject: [PATCH] Fixed bug #66 that forces all SafeMemString string representations to Empty when a size not known (like as a return value from a COM object). --- Core/InteropServices/SafeCoTaskMemString.cs | 3 +++ Core/InteropServices/SafeMemString.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/InteropServices/SafeCoTaskMemString.cs b/Core/InteropServices/SafeCoTaskMemString.cs index 8c0c0504..299a0520 100644 --- a/Core/InteropServices/SafeCoTaskMemString.cs +++ b/Core/InteropServices/SafeCoTaskMemString.cs @@ -37,6 +37,9 @@ namespace Vanara.InteropServices { } + /// Prevents a default instance of the class from being created. + private SafeCoTaskMemString() : base() { } + /// Initializes a new instance of the class. /// The PTR. /// The character set. diff --git a/Core/InteropServices/SafeMemString.cs b/Core/InteropServices/SafeMemString.cs index 9a50911c..5a040c86 100644 --- a/Core/InteropServices/SafeMemString.cs +++ b/Core/InteropServices/SafeMemString.cs @@ -186,6 +186,6 @@ namespace Vanara.InteropServices /// Returns the string value held by this instance. /// A value held by this instance or null if the handle is invalid. - public override string ToString() => IsInvalid ? null : StringHelper.GetString(handle, CharSet, Size); + public override string ToString() => IsInvalid ? null : StringHelper.GetString(handle, CharSet, Size == 0 ? long.MaxValue : (long)Size); } } \ No newline at end of file