From 6d427c51db676acce7d9352f0c814260f2913e16 Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Thu, 6 Jun 2024 17:44:36 +0200 Subject: [PATCH] replace marshal.sizeof(...) calls for primitive types with sizeof constants --- .../Ink/GestureRecognizer/NativeRecognizer.cs | 4 +-- .../Windows/Input/InputProcessorProfiles.cs | 4 +-- .../System/Windows/Media/PixelFormat.cs | 3 +- .../Internal/AppModel/AppSecurityManager.cs | 2 +- .../Internal/Printing/PrintDlgExMarshaler.cs | 3 +- .../Generated/WinRT/Marshalers.cs | 4 +-- .../Windows/Documents/ImmComposition.cs | 14 ++++----- .../Windows/Documents/InputScopeAttribute.cs | 12 ++++---- .../System/Windows/Standard/NativeMethods.cs | 6 ++-- .../Internal/Documents/PeoplePickerWrapper.cs | 3 +- .../PrintConfig/FallbackPTProvider.cs | 8 ++--- .../src/Shared/MS/Internal/Ink/Native.cs | 18 ++++++------ .../System/Windows/Automation/Condition.cs | 6 ++-- .../AutomationProxies/CommonXSendMessage.cs | 4 +-- .../CompoundFile/ContainerUtilities.cs | 29 ++----------------- 15 files changed, 47 insertions(+), 73 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs index 68103b147cf..5b73c71de48 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs @@ -505,7 +505,7 @@ StylusPointDescription reformatDescription Debug.Assert(propertyGuids.Length == StylusPointDescription.RequiredCountOfProperties); // Get the packet description - packetDescription.cbPacketSize = (uint)(propertyGuids.Length * Marshal.SizeOf(typeof(Int32))); + packetDescription.cbPacketSize = (uint)(propertyGuids.Length * sizeof(Int32)); packetDescription.cPacketProperties = (uint)propertyGuids.Length; // @@ -554,7 +554,7 @@ StylusPointDescription reformatDescription int packetCount = rawPackets.Length; if (packetCount != 0) { - countOfBytes = packetCount * Marshal.SizeOf(typeof(Int32)); + countOfBytes = packetCount * sizeof(Int32); packets = Marshal.AllocCoTaskMem(countOfBytes); Marshal.Copy(rawPackets, 0, packets, packetCount); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProcessorProfiles.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProcessorProfiles.cs index 38956f5f29b..6e68a2b5df4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProcessorProfiles.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProcessorProfiles.cs @@ -155,12 +155,10 @@ internal ArrayList InputLanguageList ArrayList arrayLang = new ArrayList(); - int sizeOfShort = Marshal.SizeOf(typeof(short)); - for (int i = 0; i < nCount; i++) { // Unmarshal each langid from short array. - short langid = Marshal.PtrToStructure((IntPtr)((Int64)langids + sizeOfShort * i)); + short langid = Marshal.PtrToStructure((IntPtr)((Int64)langids + sizeof(short) * i)); arrayLang.Add(new CultureInfo(langid)); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs index 45058f0353d..55b7b4d9fac 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs @@ -22,6 +22,7 @@ using SR=MS.Internal.PresentationCore.SR; using UnsafeNativeMethods=MS.Win32.PresentationCore.UnsafeNativeMethods; +using System.Runtime.CompilerServices; namespace System.Windows.Media { @@ -169,7 +170,7 @@ internal PixelFormat(Guid guidPixelFormat) // Compare only the first 15 bytes of the GUID. If the first // 15 bytes match the WIC pixel formats, then the 16th byte // will be the format enum value. - Debug.Assert(Marshal.SizeOf(typeof(Guid)) == 16); + Debug.Assert(Unsafe.SizeOf() == 16); int compareCount = 15; bool fBuiltIn = true; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppSecurityManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppSecurityManager.cs index 58f4f32782c..7ea040e1db7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppSecurityManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppSecurityManager.cs @@ -350,7 +350,7 @@ private static bool IsZoneElevationSettingPrompt(Uri target) _secMgr.ProcessUrlAction(targetString, NativeMethods.URLACTION_FEATURE_ZONE_ELEVATION, (byte*)&policy, - Marshal.SizeOf(typeof(int)), + sizeof(int), null, 0, NativeMethods.PUAF_NOUI, diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Printing/PrintDlgExMarshaler.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Printing/PrintDlgExMarshaler.cs index 4156cbcc12e..0c52f92bd19 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Printing/PrintDlgExMarshaler.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Printing/PrintDlgExMarshaler.cs @@ -693,8 +693,7 @@ IntPtr unmanagedBuffer bool Is64Bit() { - IntPtr temp = IntPtr.Zero; - return Marshal.SizeOf(temp) == 8; + return IntPtr.Size == sizeof(long); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/Marshalers.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/Marshalers.cs index ccbf13294a0..97fbbc2f86a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/Marshalers.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/Marshalers.cs @@ -148,7 +148,7 @@ public static unsafe MarshalerArray CreateMarshalerArray(string[] array) try { var length = array.Length; - m._array = Marshal.AllocCoTaskMem(length * Marshal.SizeOf()); + m._array = Marshal.AllocCoTaskMem(length * IntPtr.Size); m._marshalers = new MarshalString[length]; var elements = (IntPtr*)m._array.ToPointer(); for (int i = 0; i < length; i++) @@ -215,7 +215,7 @@ public static unsafe (int length, IntPtr data) FromManagedArray(string[] array) try { var length = array.Length; - data = Marshal.AllocCoTaskMem(length * Marshal.SizeOf()); + data = Marshal.AllocCoTaskMem(length * IntPtr.Size); var elements = (IntPtr*)data; for (i = 0; i < length; i++) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs index f23a305f946..c243e9a4896 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs @@ -430,7 +430,7 @@ private void OnWmImeComposition(IntPtr hwnd, IntPtr lParam, ref bool handled) size = UnsafeNativeMethods.ImmGetCompositionString(new HandleRef(this, himc), NativeMethods.GCS_RESULTSTR, IntPtr.Zero, 0); if (size > 0) { - result = new char[size / Marshal.SizeOf(typeof(short))]; + result = new char[size / sizeof(short)]; // 3rd param is out and contains actual result of this call. // suppress Presharp 6031. @@ -447,7 +447,7 @@ private void OnWmImeComposition(IntPtr hwnd, IntPtr lParam, ref bool handled) size = UnsafeNativeMethods.ImmGetCompositionString(new HandleRef(this, himc), NativeMethods.GCS_COMPSTR, IntPtr.Zero, 0); if (size > 0) { - composition = new char[size / Marshal.SizeOf(typeof(short))]; + composition = new char[size / sizeof(short)]; // 3rd param is out and contains actual result of this call. // suppress Presharp 6031. #pragma warning suppress 6031 @@ -477,7 +477,7 @@ private void OnWmImeComposition(IntPtr hwnd, IntPtr lParam, ref bool handled) size = UnsafeNativeMethods.ImmGetCompositionString(new HandleRef(this, himc), NativeMethods.GCS_COMPATTR, IntPtr.Zero, 0); if (size > 0) { - attributes = new byte[size / Marshal.SizeOf(typeof(byte))]; + attributes = new byte[size / sizeof(byte)]; // 3rd param is out and contains actual result of this call. // suppress Presharp 6031. #pragma warning suppress 6031 @@ -1349,7 +1349,7 @@ private IntPtr OnWmImeRequest_ReconvertString(IntPtr lParam, ref bool handled, b string target = range.Text; - int requestSize = Marshal.SizeOf(typeof(NativeMethods.RECONVERTSTRING)) + (target.Length * Marshal.SizeOf(typeof(short))) + ((_maxSrounding + 1) * Marshal.SizeOf(typeof(short)) * 2); + int requestSize = Marshal.SizeOf(typeof(NativeMethods.RECONVERTSTRING)) + (target.Length * sizeof(short)) + ((_maxSrounding + 1) * sizeof(short) * 2); IntPtr lret = new IntPtr(requestSize); if (lParam != IntPtr.Zero) @@ -1365,9 +1365,9 @@ private IntPtr OnWmImeRequest_ReconvertString(IntPtr lParam, ref bool handled, b reconv.dwStrLen = surrounding.Length; // in char count reconv.dwStrOffset = Marshal.SizeOf(typeof(NativeMethods.RECONVERTSTRING)); // in byte count reconv.dwCompStrLen = target.Length; // in char count - reconv.dwCompStrOffset = offsetStart * Marshal.SizeOf(typeof(short)); // in byte count + reconv.dwCompStrOffset = offsetStart * sizeof(short); // in byte count reconv.dwTargetStrLen = target.Length; // in char count - reconv.dwTargetStrOffset = offsetStart * Marshal.SizeOf(typeof(short)); // in byte count + reconv.dwTargetStrOffset = offsetStart * sizeof(short); // in byte count if (!fDocFeed) { @@ -1543,7 +1543,7 @@ private IntPtr OnWmImeRequest_ConfirmReconvertString(IntPtr lParam, ref bool han ITextPointer start = range.Start.CreatePointer(LogicalDirection.Backward); // Move the start point to new dwCompStrOffset. - start = MoveToNextCharPos(start, (reconv.dwCompStrOffset - _reconv.dwCompStrOffset) / Marshal.SizeOf(typeof(short))); + start = MoveToNextCharPos(start, (reconv.dwCompStrOffset - _reconv.dwCompStrOffset) / sizeof(short)); // Create the end position and move this as dwCompStrLen. ITextPointer end = start.CreatePointer(LogicalDirection.Forward); end = MoveToNextCharPos(end, reconv.dwCompStrLen); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InputScopeAttribute.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InputScopeAttribute.cs index 08bd9b49cb2..314582057d2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InputScopeAttribute.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InputScopeAttribute.cs @@ -62,7 +62,7 @@ public void GetInputScopes(out IntPtr ppinputscopes, out int count) count = _inputScope.Names.Count; try { - ppinputscopes = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Int32)) * count); + ppinputscopes = Marshal.AllocCoTaskMem(sizeof(Int32) * count); } catch (OutOfMemoryException) { @@ -72,12 +72,12 @@ public void GetInputScopes(out IntPtr ppinputscopes, out int count) for (int i = 0; i < count; i++) { Marshal.WriteInt32(ppinputscopes, offset, (Int32)((InputScopeName)_inputScope.Names[i]).NameValue); - offset += Marshal.SizeOf(typeof(Int32)); + offset += sizeof(Int32); } } else { - ppinputscopes = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Int32)) * 1); + ppinputscopes = Marshal.AllocCoTaskMem(sizeof(Int32) * 1); Marshal.WriteInt32(ppinputscopes, (Int32)InputScopeNameValue.Default); count = 1; } @@ -90,7 +90,7 @@ public int GetPhrase(out IntPtr ppbstrPhrases, out int count) count = _inputScope == null ? 0 : _inputScope.PhraseList.Count; try { - ppbstrPhrases = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr))*count); + ppbstrPhrases = Marshal.AllocCoTaskMem(IntPtr.Size * count); } catch (OutOfMemoryException) { @@ -111,13 +111,13 @@ public int GetPhrase(out IntPtr ppbstrPhrases, out int count) for (int j=0; j < i; j++) { Marshal.FreeBSTR(Marshal.ReadIntPtr(ppbstrPhrases, offset)); - offset += Marshal.SizeOf(typeof(IntPtr)); + offset += IntPtr.Size; } throw new COMException(SR.InputScopeAttribute_E_OUTOFMEMORY, NativeMethods.E_OUTOFMEMORY); } Marshal.WriteIntPtr(ppbstrPhrases , offset, pbstr); - offset += Marshal.SizeOf(typeof(IntPtr)); + offset += IntPtr.Size; } return count > 0 ? NativeMethods.S_OK : NativeMethods.S_FALSE; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/NativeMethods.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/NativeMethods.cs index 3d047367d23..9158e2eae57 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/NativeMethods.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/NativeMethods.cs @@ -2403,7 +2403,7 @@ public static string[] CommandLineToArgvW(string cmdLine) for (int i = 0; i < numArgs; i++) { - IntPtr currArg = Marshal.ReadIntPtr(argv, i * Marshal.SizeOf(typeof(IntPtr))); + IntPtr currArg = Marshal.ReadIntPtr(argv, i * IntPtr.Size); result[i] = Marshal.PtrToStringUni(currArg); } @@ -2628,7 +2628,7 @@ public static HRESULT DwmSetWindowAttributeSystemBackdropType(IntPtr hwnd, DWMSB { Assert.IsTrue(Utility.IsWindows11_22H2OrNewer); var dwmWindowAttribute = (int)dwBackdropType; - return _DwmSetWindowAttribute(hwnd, DWMWA.SYSTEMBACKDROP_TYPE, ref dwmWindowAttribute, Marshal.SizeOf(typeof(int))); + return _DwmSetWindowAttribute(hwnd, DWMWA.SYSTEMBACKDROP_TYPE, ref dwmWindowAttribute, sizeof(int)); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] @@ -2636,7 +2636,7 @@ public static bool DwmSetWindowAttributeUseImmersiveDarkMode(IntPtr hwnd, bool u { Assert.IsTrue(Utility.IsWindows11_22H2OrNewer); var pvAttribute = useImmersiveDarkMode ? 0x1 : 0x0; - var dwmResult = _DwmSetWindowAttribute(hwnd, DWMWA.USE_IMMERSIVE_DARK_MODE, ref pvAttribute, Marshal.SizeOf(typeof(int))); + var dwmResult = _DwmSetWindowAttribute(hwnd, DWMWA.USE_IMMERSIVE_DARK_MODE, ref pvAttribute, sizeof(int)); return dwmResult == HRESULT.S_OK; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/PeoplePickerWrapper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/PeoplePickerWrapper.cs index e8a4d110e45..216c8d803f4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/PeoplePickerWrapper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/PeoplePickerWrapper.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.DirectoryServices; using System.Globalization; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Windows.TrustUI; @@ -513,7 +514,7 @@ public void Dispose() /// DsObjects array. /// private static readonly int _dsObjectArrayFieldOffset = - Marshal.SizeOf(typeof(Guid)) + Marshal.SizeOf(typeof(UInt32)); + Unsafe.SizeOf() + sizeof(UInt32); /// /// The size of a DsObject. diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs index 6470ba1faa3..fa89c631ce3 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs @@ -756,28 +756,28 @@ public void Callback(HGlobalBuffer pPrinterBuffer) IntPtr ptr = pPrinterBuffer.Handle.DangerousGetHandle(); // LPTSTR pPrinterName; - IntPtr pPrinterName = Marshal.ReadIntPtr(ptr, 1 * Marshal.SizeOf(typeof(IntPtr))); + IntPtr pPrinterName = Marshal.ReadIntPtr(ptr, 1 * IntPtr.Size); if (pPrinterName != IntPtr.Zero) { PRINTER_INFO_2.pPrinterName = Marshal.PtrToStringUni(pPrinterName); } // LPTSTR pPortName; - IntPtr pPortName = Marshal.ReadIntPtr(ptr, 3 * Marshal.SizeOf(typeof(IntPtr))); + IntPtr pPortName = Marshal.ReadIntPtr(ptr, 3 * IntPtr.Size); if (pPortName != IntPtr.Zero) { PRINTER_INFO_2.pPortName = Marshal.PtrToStringUni(pPortName); } // LPTSTR pDriverName; - IntPtr pDriverName = Marshal.ReadIntPtr(ptr, 4 * Marshal.SizeOf(typeof(IntPtr))); + IntPtr pDriverName = Marshal.ReadIntPtr(ptr, 4 * IntPtr.Size); if (pDriverName != IntPtr.Zero) { PRINTER_INFO_2.pDriverName = Marshal.PtrToStringUni(pDriverName); } // LPDEVMODE pDevMode; - IntPtr pDevMode = Marshal.ReadIntPtr(ptr, 7 * Marshal.SizeOf(typeof(IntPtr))); + IntPtr pDevMode = Marshal.ReadIntPtr(ptr, 7 * IntPtr.Size); if (pDevMode != IntPtr.Zero) { PRINTER_INFO_2.pDevMode = DevMode.FromIntPtr(pDevMode); diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Ink/Native.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Ink/Native.cs index 13814f1cdc4..2616e023737 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Ink/Native.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Ink/Native.cs @@ -4,7 +4,7 @@ using System; using System.Security; -using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; namespace MS.Internal.Ink { @@ -18,14 +18,14 @@ static Native() // NOTICE-2005/10/14-WAYNEZEN, // Make sure those lengths are indepentent from the 32bit or 64bit platform. Otherwise it could // break the ISF format. - SizeOfInt = (uint)Marshal.SizeOf(typeof(int)); - SizeOfUInt = (uint)Marshal.SizeOf(typeof(uint)); - SizeOfUShort = (uint)Marshal.SizeOf(typeof(ushort)); - SizeOfByte = (uint)Marshal.SizeOf(typeof(byte)); - SizeOfFloat = (uint)Marshal.SizeOf(typeof(float)); - SizeOfDouble = (uint)Marshal.SizeOf(typeof(double)); - SizeOfGuid = (uint)Marshal.SizeOf(typeof(Guid)); - SizeOfDecimal = (uint)Marshal.SizeOf(typeof(decimal)); + SizeOfInt = sizeof(int); + SizeOfUInt = sizeof(uint); + SizeOfUShort = sizeof(ushort); + SizeOfByte = sizeof(byte); + SizeOfFloat = sizeof(float); + SizeOfDouble = sizeof(double); + SizeOfGuid = (uint)Unsafe.SizeOf(); + SizeOfDecimal = sizeof(decimal); } internal static readonly uint SizeOfInt; // Size of an int diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/Condition.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/Condition.cs index ab21ee447af..5b60ecfea32 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/Condition.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/Condition.cs @@ -57,17 +57,15 @@ internal static SafeConditionMemoryHandle AllocateConditionHandle(T uiaCondit // used by And/Or conditions to allocate an array of pointers to other conditions - internal static SafeConditionMemoryHandle AllocateConditionArrayHandle(Condition [] conditions) + internal static SafeConditionMemoryHandle AllocateConditionArrayHandle(Condition[] conditions) { // Allocate SafeHandle first to avoid failure later. SafeConditionMemoryHandle sh = new SafeConditionMemoryHandle(); - int intPtrSize = Marshal.SizeOf(typeof(IntPtr)); - try { } finally { - IntPtr mem = Marshal.AllocCoTaskMem(conditions.Length * intPtrSize); + IntPtr mem = Marshal.AllocCoTaskMem(conditions.Length * IntPtr.Size); sh.SetHandle(mem); } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/CommonXSendMessage.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/CommonXSendMessage.cs index 9cdd9217cd8..ee4ddccca4c 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/CommonXSendMessage.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/CommonXSendMessage.cs @@ -153,7 +153,7 @@ internal static void GetProcessTypes(IntPtr hwnd, out ProcessorTypes localBitnes // Local process is running in native mode // Check the machine bitness. - if (Marshal.SizeOf(hwnd) == sizeof(int)) + if (IntPtr.Size == sizeof(int)) { // The machine bitness is 32-bit. @@ -1512,7 +1512,7 @@ private static bool IsWOW64Process(IntPtr hwnd) // NtQueryInformationProcess is available for use in Windows 2000 and Windows XP. // It may be altered or unavailable in subsequent versions. Applications should use the alternate functions ulong infoWOW64 = 0; - int status = UnsafeNativeMethods.NtQueryInformationProcess(hProcess, UnsafeNativeMethods.ProcessWow64Information, ref infoWOW64, Marshal.SizeOf(typeof(ulong)), null); + int status = UnsafeNativeMethods.NtQueryInformationProcess(hProcess, UnsafeNativeMethods.ProcessWow64Information, ref infoWOW64, sizeof(ulong), null); if (NT_ERROR(status)) { // Query failed. Assume not running under WOW64. diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs index 071dfc8305f..4fee4453460 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs @@ -34,13 +34,13 @@ namespace MS.Internal.IO.Packaging.CompoundFile /// static internal class ContainerUtilities { - static private readonly Int32 _int16Size = SizeOfInt16(); - static private readonly Int32 _int32Size = SizeOfInt32(); + static private readonly Int32 _int16Size = sizeof(Int16); + static private readonly Int32 _int32Size = sizeof(Int32); static private readonly byte[] _paddingBuf = new byte[4]; // for writing DWORD padding #if !PBTCOMPILER - static private readonly Int32 _int64Size = SizeOfInt64(); + static private readonly Int32 _int64Size = sizeof(Int64); /// Used by ConvertBackSlashPathToStringArrayPath and /// ConvertStringArrayPathToBackSlashPath to separate path elements. @@ -272,29 +272,6 @@ static internal void CheckAgainstNull(object paramRef, throw new ArgumentNullException(testStringIdentifier); } -#if !PBTCOMPILER - -#endif - private static int SizeOfInt16() - { - return Marshal.SizeOf(typeof(Int16)); - } - -#if !PBTCOMPILER - -#endif - private static int SizeOfInt32() - { - return Marshal.SizeOf(typeof(Int32)); - } - -#if !PBTCOMPILER - private static int SizeOfInt64() - { - return Marshal.SizeOf(typeof(Int64)); - } -#endif - #if !PBTCOMPILER /// /// Interprets a single string by treating it as a set of names