Simplify LOGFONT marshalling (dotnet/corefx#42011)
authorJan Kotas <jkotas@microsoft.com>
Wed, 23 Oct 2019 01:41:21 +0000 (18:41 -0700)
committerStephen Toub <stoub@microsoft.com>
Wed, 23 Oct 2019 01:41:21 +0000 (21:41 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/86972eac7ce0707073b724d71be2927fc1fe225f

src/libraries/System.Drawing.Common/src/System/Drawing/Font.Windows.cs

index ba168e8..d52f7fd 100644 (file)
@@ -311,22 +311,7 @@ namespace System.Drawing
             // Now that we know the marshalled size is the same as LOGFONT, copy in the data
             logFont = new SafeNativeMethods.LOGFONT();
 
-            try
-            {
-                GCHandle handle = GCHandle.Alloc(lf, GCHandleType.Pinned);
-                Buffer.MemoryCopy((byte*)handle.AddrOfPinnedObject(), &logFont, nativeSize, nativeSize);
-                handle.Free();
-            }
-            catch (ArgumentException)
-            {
-                // If the type isn't blittable it won't be able to be pinned with GCHandle. Try
-                // to use the marshaller to copy the "native" representation instead.
-                //
-                // This happens for classes or structs that have reference types as members.
-                // Marshal.StructureToPtr() will *not* work with blittable structs (which are
-                // handled in the try block above).
-                Marshal.StructureToPtr(lf, new IntPtr(&logFont), fDeleteOld: false);
-            }
+            Marshal.StructureToPtr(lf, new IntPtr(&logFont), fDeleteOld: false);
 
             return FromLogFontInternal(ref logFont, hdc);
         }