From 63f7a1d201ec13c1da4801c39a8826971c91ac6d Mon Sep 17 00:00:00 2001 From: Matt Haynie Date: Sun, 28 Feb 2021 17:57:02 -0800 Subject: [PATCH] Create WinBase.File.cs (#213) MAX_PATH is not a hard limit on the maximum length of a file path. Using Windows 10, I have a file path that is ~378 chars long, and an exception is thrown in the local method AddCap because the code attempts to increase the size of the StringBuilder beyond the 261 chars that was specified in the constructor. This change just removes the hard upper limit cap on that length. --- PInvoke/Kernel32/WinBase.File.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PInvoke/Kernel32/WinBase.File.cs b/PInvoke/Kernel32/WinBase.File.cs index 894193c6..098a8c57 100644 --- a/PInvoke/Kernel32/WinBase.File.cs +++ b/PInvoke/Kernel32/WinBase.File.cs @@ -3177,7 +3177,7 @@ namespace Vanara.PInvoke /// List of strings returned by and methods. private static IEnumerable EnumFindMethods(FindFirstDelegate first, FindNextDelegate next, uint strSz = MAX_PATH + 1, uint done = Win32Error.ERROR_HANDLE_EOF) where THandle : SafeHandle { - var sb = new StringBuilder((int)strSz, (int)strSz); + var sb = new StringBuilder((int)strSz); THandle h; while ((h = first(sb, ref strSz)).IsInvalid) { @@ -5153,4 +5153,4 @@ namespace Vanara.PInvoke protected override bool InternalReleaseHandle() => FindVolumeMountPointClose(handle); } } -} \ No newline at end of file +}