Add [Out] to a couple of StringBuilders in DllImports
authorstephentoub <stoub@microsoft.com>
Thu, 8 Oct 2015 17:14:21 +0000 (13:14 -0400)
committerstephentoub <stoub@microsoft.com>
Thu, 8 Oct 2015 17:14:21 +0000 (13:14 -0400)
I audited all of the StringBuilders being used in P/Invokes in mscorlib.  Almost all of them were correctly annotated as to their direction of needed marshaling.  Two weren't.

src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs

index 624f8aa..fdd06e2 100644 (file)
@@ -45,14 +45,14 @@ namespace Microsoft.Win32 {
                                      [MarshalAs(UnmanagedType.LPWStr)]
                                      StringBuilder language,
                                      ref int languageLength,
-                                     [MarshalAs(UnmanagedType.LPWStr)]
+                                     [Out, MarshalAs(UnmanagedType.LPWStr)]
                                      StringBuilder fileMuiPath,
                                      ref int fileMuiPathLength,
                                      ref Int64 enumerator);
 
 
         [DllImport(Win32Native.USER32, EntryPoint="LoadStringW",  SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
-        internal static extern int LoadString(SafeLibraryHandle handle, int id, StringBuilder buffer, int bufferLength);
+        internal static extern int LoadString(SafeLibraryHandle handle, int id, [Out] StringBuilder buffer, int bufferLength);
 
         [DllImport(Win32Native.KERNEL32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
         internal static extern SafeLibraryHandle LoadLibraryEx(string libFilename, IntPtr reserved, int flags);