diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DpiChangedEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DpiChangedEventArgs.cs index ee8211c01412b32da5f7e21027ceb3ff1b1b599c..5b621742a5e3797099e95a1d97e840c7964188af 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DpiChangedEventArgs.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DpiChangedEventArgs.cs @@ -10,6 +10,7 @@ // different DPI, or the dpi of the current monitor changes. using System.ComponentModel; +using System.Runtime.InteropServices; using System.Security; using System.Threading; using System.Windows.Interop; @@ -48,7 +49,7 @@ internal HwndDpiChangedEventArgs(double oldDpiX, double oldDpiY, double newDpiX, { OldDpi = new DpiScale(oldDpiX / DpiUtil.DefaultPixelsPerInch, oldDpiY / DpiUtil.DefaultPixelsPerInch); NewDpi = new DpiScale(newDpiX / DpiUtil.DefaultPixelsPerInch, newDpiY / DpiUtil.DefaultPixelsPerInch); - NativeMethods.RECT suggestedRect = (NativeMethods.RECT)UnsafeNativeMethods.PtrToStructure(lParam, typeof(NativeMethods.RECT)); + NativeMethods.RECT suggestedRect = Marshal.PtrToStructure(lParam); this.SuggestedRect = new Rect((double)suggestedRect.left, (double)suggestedRect.top, (double)suggestedRect.Width, (double)suggestedRect.Height); } 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 05b82a14dfa26c0603b97d645d61ed76007f71af..38956f5f29b35a2c0d24dbd5d468f5f586686624 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 @@ -160,7 +160,7 @@ internal ArrayList InputLanguageList for (int i = 0; i < nCount; i++) { // Unmarshal each langid from short array. - short langid = (short)Marshal.PtrToStructure((IntPtr)((Int64)langids + sizeOfShort * i), typeof(short)); + short langid = Marshal.PtrToStructure((IntPtr)((Int64)langids + sizeOfShort * i)); arrayLang.Add(new CultureInfo(langid)); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs index 3c14f02db0edea6bffd1eb2fb5d4fddb699f4bd1..4c2a6916e3cfef51a641d19767e1f50290af385f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs @@ -1368,7 +1368,7 @@ private void Process_WM_WINDOWPOSCHANGING(UIElement rootUIElement, IntPtr hwnd, // Get WINDOWPOS structure data from lParam; it contains information about the window's // new size and position. - NativeMethods.WINDOWPOS windowPos = (NativeMethods.WINDOWPOS)UnsafeNativeMethods.PtrToStructure(lParam, typeof(NativeMethods.WINDOWPOS)); + NativeMethods.WINDOWPOS windowPos = Marshal.PtrToStructure(lParam); bool sizeChanged = false; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs index bc1bde7b312c601d39bc955ebcc197e3f26d137c..0cfa9c2191829b5dbece17382b0cc019539149b4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs @@ -876,7 +876,7 @@ private bool HandleDpiChangedMessage(IntPtr wParam, IntPtr lParam) if (oldDpi != newDpi) { var nativeRect = - UnsafeNativeMethods.PtrToStructure(lParam); + Marshal.PtrToStructure(lParam); var suggestedRect = new Rect(nativeRect.left, nativeRect.top, nativeRect.Width, nativeRect.Height); @@ -1870,7 +1870,7 @@ private void UpdateWindowPos(IntPtr lParam) // size or position changed. If so, we need to pass this information to // the render thread. // - NativeMethods.WINDOWPOS windowPos = (NativeMethods.WINDOWPOS)UnsafeNativeMethods.PtrToStructure(lParam, typeof(NativeMethods.WINDOWPOS)); + NativeMethods.WINDOWPOS windowPos = Marshal.PtrToStructure(lParam); bool isMove = (windowPos.flags & NativeMethods.SWP_NOMOVE) == 0; bool isSize = (windowPos.flags & NativeMethods.SWP_NOSIZE) == 0; bool positionChanged = (isMove || isSize); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ImageSourceConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ImageSourceConverter.cs index 2c3c2695bc8e06cae03ac9058e83d57af5531c44..990ed7127bc33c08ece980457c4f31abe1eb37f2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ImageSourceConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ImageSourceConverter.cs @@ -261,7 +261,7 @@ private unsafe Stream GetBitmapStream(byte[] rawData) // // http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q175261 // - OBJECTHEADER pHeader = (OBJECTHEADER)Marshal.PtrToStructure(addr, typeof(OBJECTHEADER)); + OBJECTHEADER pHeader = Marshal.PtrToStructure(addr); // // "PBrush" should be the 6 chars after position 12 as well. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSource.cs index 71bc4069302240d4d927c73191eaf8642e45ad70..2e03153eeacea14bf28334b8b1c262a5324da54c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSource.cs @@ -1847,7 +1847,7 @@ int IWICBitmapSource.CopyPixels(IntPtr prc, int cbStride, int cbPixels, IntPtr p } else { - rc = (Int32Rect)Marshal.PtrToStructure(prc, typeof(Int32Rect)); + rc = Marshal.PtrToStructure(prc); } int rectHeight, rectWidth; 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 d5be8f8c31dcc7ef6299f7c1fbf576deb7da7dcf..4156cbcc12e5058db5ee5e57badb0657047e87ed 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 @@ -235,9 +235,7 @@ bool disposing // if (!Is64Bit()) { - NativeMethods.PRINTDLGEX32 pdex = (NativeMethods.PRINTDLGEX32)Marshal.PtrToStructure( - unmanagedBuffer, - typeof(NativeMethods.PRINTDLGEX32)); + NativeMethods.PRINTDLGEX32 pdex = Marshal.PtrToStructure(unmanagedBuffer); devModeHandle = pdex.hDevMode; devNamesHandle = pdex.hDevNames; flags = pdex.Flags; @@ -245,9 +243,7 @@ bool disposing } else { - NativeMethods.PRINTDLGEX64 pdex = (NativeMethods.PRINTDLGEX64)Marshal.PtrToStructure( - unmanagedBuffer, - typeof(NativeMethods.PRINTDLGEX64)); + NativeMethods.PRINTDLGEX64 pdex = Marshal.PtrToStructure(unmanagedBuffer); devModeHandle = pdex.hDevMode; devNamesHandle = pdex.hDevNames; flags = pdex.Flags; @@ -261,9 +257,7 @@ bool disposing if (((flags & NativeMethods.PD_PAGENUMS) == NativeMethods.PD_PAGENUMS) && (pageRangePtr != IntPtr.Zero)) { - NativeMethods.PRINTPAGERANGE pageRangeStruct = (NativeMethods.PRINTPAGERANGE)Marshal.PtrToStructure( - pageRangePtr, - typeof(NativeMethods.PRINTPAGERANGE)); + NativeMethods.PRINTPAGERANGE pageRangeStruct = Marshal.PtrToStructure(pageRangePtr); pageRange = new PageRange((int)pageRangeStruct.nFromPage, (int)pageRangeStruct.nToPage); } @@ -282,9 +276,7 @@ bool disposing { pDevNames = UnsafeNativeMethods.GlobalLock(devNamesHandle); - NativeMethods.DEVNAMES devNames = (NativeMethods.DEVNAMES)Marshal.PtrToStructure( - pDevNames, - typeof(NativeMethods.DEVNAMES)); + NativeMethods.DEVNAMES devNames = Marshal.PtrToStructure(pDevNames); int devNamesOffset = checked(devNames.wDeviceOffset * Marshal.SystemDefaultCharSize); printerName = Marshal.PtrToStringAuto(pDevNames + devNamesOffset); } @@ -380,9 +372,7 @@ string printQueueName { pDevMode = UnsafeNativeMethods.GlobalLock(devModeHandle); - NativeMethods.DEVMODE devMode = (NativeMethods.DEVMODE)Marshal.PtrToStructure( - pDevMode, - typeof(NativeMethods.DEVMODE)); + NativeMethods.DEVMODE devMode = Marshal.PtrToStructure(pDevMode); devModeData = new byte[devMode.dmSize + devMode.dmDriverExtra]; Marshal.Copy(pDevMode, devModeData, 0, devModeData.Length); } @@ -428,16 +418,12 @@ IntPtr unmanagedBuffer // if (!Is64Bit()) { - NativeMethods.PRINTDLGEX32 pdex = (NativeMethods.PRINTDLGEX32)Marshal.PtrToStructure( - unmanagedBuffer, - typeof(NativeMethods.PRINTDLGEX32)); + NativeMethods.PRINTDLGEX32 pdex = Marshal.PtrToStructure(unmanagedBuffer); result = pdex.dwResultAction; } else { - NativeMethods.PRINTDLGEX64 pdex = (NativeMethods.PRINTDLGEX64)Marshal.PtrToStructure( - unmanagedBuffer, - typeof(NativeMethods.PRINTDLGEX64)); + NativeMethods.PRINTDLGEX64 pdex = Marshal.PtrToStructure(unmanagedBuffer); result = pdex.dwResultAction; } @@ -668,18 +654,14 @@ IntPtr unmanagedBuffer // if (!Is64Bit()) { - NativeMethods.PRINTDLGEX32 pdex = (NativeMethods.PRINTDLGEX32)Marshal.PtrToStructure( - unmanagedBuffer, - typeof(NativeMethods.PRINTDLGEX32)); + NativeMethods.PRINTDLGEX32 pdex = Marshal.PtrToStructure(unmanagedBuffer); devModeHandle = pdex.hDevMode; devNamesHandle = pdex.hDevNames; pageRangePtr = pdex.lpPageRanges; } else { - NativeMethods.PRINTDLGEX64 pdex = (NativeMethods.PRINTDLGEX64)Marshal.PtrToStructure( - unmanagedBuffer, - typeof(NativeMethods.PRINTDLGEX64)); + NativeMethods.PRINTDLGEX64 pdex = Marshal.PtrToStructure(unmanagedBuffer); devModeHandle = pdex.hDevMode; devNamesHandle = pdex.hDevNames; pageRangePtr = pdex.lpPageRanges; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs index 1b26d38d1e7213e34ffe3ae6dc2863d44ccf870a..181ebe2c7ceeb63ba1d91b40928df902f3a563f8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs @@ -589,7 +589,7 @@ protected override IntPtr HookProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr l // } // // Convert the pointer to our OFNOTIFY stored in lparam to an object using PtrToStructure. - NativeMethods.OFNOTIFY notify = (NativeMethods.OFNOTIFY)UnsafeNativeMethods.PtrToStructure(lParam, typeof(NativeMethods.OFNOTIFY)); + NativeMethods.OFNOTIFY notify = Marshal.PtrToStructure(lParam); // WM_NOTIFY indicates that the dialog is sending us a notification message. // notify.hdr_code is an int defining which notification is being received. @@ -623,8 +623,7 @@ protected override IntPtr HookProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr l // Retrieve the OPENFILENAME structure from the OFNOTIFY structure // so we can access the CharBuffer inside it. - NativeMethods.OPENFILENAME_I ofn = (NativeMethods.OPENFILENAME_I) - UnsafeNativeMethods.PtrToStructure(notify.lpOFN, typeof(NativeMethods.OPENFILENAME_I)); + NativeMethods.OPENFILENAME_I ofn = Marshal.PtrToStructure(notify.lpOFN); // Get the buffer size required to store the selected file names. @@ -1162,7 +1161,7 @@ internal string[] FileNamesInternal /// private bool DoFileOk(IntPtr lpOFN) { - NativeMethods.OPENFILENAME_I ofn = (NativeMethods.OPENFILENAME_I)UnsafeNativeMethods.PtrToStructure(lpOFN, typeof(NativeMethods.OPENFILENAME_I)); + NativeMethods.OPENFILENAME_I ofn = Marshal.PtrToStructure(lpOFN); // While processing the results we get from the OPENFILENAME struct, // we will adjust several properties of our own class to reflect the 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 1feda7094c5e702fd2bebd61222f834ca0193963..f23a305f946e8091403fe6c4a4d6e45b01464baf 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 @@ -1358,7 +1358,7 @@ private IntPtr OnWmImeRequest_ReconvertString(IntPtr lParam, ref bool handled, b string surrounding = GetSurroundingText(range, out offsetStart); // Create RECONVERTSTRING structure from lParam. - NativeMethods.RECONVERTSTRING reconv = (NativeMethods.RECONVERTSTRING)Marshal.PtrToStructure(lParam, typeof(NativeMethods.RECONVERTSTRING)); + NativeMethods.RECONVERTSTRING reconv = Marshal.PtrToStructure(lParam); reconv.dwSize = requestSize; reconv.dwVersion = 0; // must be 0 @@ -1520,7 +1520,7 @@ private IntPtr OnWmImeRequest_ConfirmReconvertString(IntPtr lParam, ref bool han return IntPtr.Zero; } - NativeMethods.RECONVERTSTRING reconv = (NativeMethods.RECONVERTSTRING)Marshal.PtrToStructure(lParam, typeof(NativeMethods.RECONVERTSTRING)); + NativeMethods.RECONVERTSTRING reconv = Marshal.PtrToStructure(lParam); // If the entire string in RECONVERTSTRING has been changed, we don't handle it. if (_reconv.dwStrLen != reconv.dwStrLen) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs index bbceb4d9af2e143974e9f63afa89cbc943f0b066..4819c8e281ef83b3cdb06e6de8590c24570f38b5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs @@ -588,7 +588,7 @@ private IntPtr _HandleNCCalcSize(WM uMsg, IntPtr wParam, IntPtr lParam, out bool #else Thickness windowResizeBorderThicknessDevice = DpiHelper.LogicalThicknessToDevice(SystemParameters2.Current.WindowResizeBorderThickness, dpi.DpiScaleX, dpi.DpiScaleY); #endif - var rcClientArea = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT)); + var rcClientArea = Marshal.PtrToStructure(lParam); if (Utility.IsFlagSet((int)_chromeInfo.NonClientFrameEdges, (int)NonClientFrameEdges.Top)) { rcClientArea.Top += (int)windowResizeBorderThicknessDevice.Top; @@ -751,7 +751,7 @@ private IntPtr _HandleWindowPosChanged(WM uMsg, IntPtr wParam, IntPtr lParam, ou // reliably use it to react to the window being shown or hidden. Assert.IsNotDefault(lParam); - var wp = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS)); + var wp = Marshal.PtrToStructure(lParam); // We only care to take action when the window dimensions are changing. // Otherwise, we may get a StackOverflowException. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/MessageWindow.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/MessageWindow.cs index ecac3de7d20436915ae5690d0cf7595e7a39de06..4cfa96b3ccd716086cde0948a41f132b55b7df53 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/MessageWindow.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/MessageWindow.cs @@ -150,7 +150,7 @@ private static IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam if (msg == WM.CREATE) { - var createStruct = (CREATESTRUCT)Marshal.PtrToStructure(lParam, typeof(CREATESTRUCT)); + var createStruct = Marshal.PtrToStructure(lParam); GCHandle gcHandle = GCHandle.FromIntPtr(createStruct.lpCreateParams); hwndWrapper = (MessageWindow)gcHandle.Target; s_windowLookup.Add(hwnd, hwndWrapper); 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 6bfde0545edaf52b495f1b8969b87726e81c09a0..0380e7b17ba57f285b79c09977884d42443f6f27 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 @@ -331,10 +331,7 @@ internal DsObjectNamesWrapper(System.IO.MemoryStream dataStream) //Get a DsObjectNames structure out of the pointer we //were handed. - _dsObjectNames = - (UnsafeNativeMethods.DsObjectNames)Marshal.PtrToStructure( - _ptrToDsObjectNames, typeof(UnsafeNativeMethods.DsObjectNames)); - + _dsObjectNames = Marshal.PtrToStructure(_ptrToDsObjectNames); } /// @@ -456,12 +453,9 @@ private UnsafeNativeMethods.DsObject GetDsObjectForIndex(int index) index * _sizeOfDsObject); //Marshal that to a DsObject structure. - UnsafeNativeMethods.DsObject dsObject = - (UnsafeNativeMethods.DsObject)Marshal.PtrToStructure(offset, - typeof(UnsafeNativeMethods.DsObject)); + UnsafeNativeMethods.DsObject dsObject = Marshal.PtrToStructure(offset); return dsObject; - } /// diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs index d2c496698320141e45a2c6a75e2f25c3fc17b2fa..316d03bd62e24ae826afa4352d2937c5c226a880 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs @@ -4628,11 +4628,11 @@ public void SuppressFinalize() return (val != IntPtr.Zero); case (int)tagVT.VT_VARIANT: - VARIANT varStruct = (VARIANT)UnsafeNativeMethods.PtrToStructure(val, typeof(VARIANT)); + VARIANT varStruct = Marshal.PtrToStructure(val); return varStruct.ToObject(); case (int)tagVT.VT_CLSID: //Debug.Fail("PtrToStructure will not work with System.Guid..."); - Guid guid =(Guid)UnsafeNativeMethods.PtrToStructure(val, typeof(Guid)); + Guid guid = Marshal.PtrToStructure(val); return guid; case (int)tagVT.VT_FILETIME: diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs index dfc9687746fccdfbb971b82a179ffa093a3f841e..158c295fab08cda2cda87e5a13feb485132541f1 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs @@ -46,23 +46,6 @@ namespace MS.Win32 internal partial class UnsafeNativeMethods { - // For some reason "PtrToStructure" requires super high permission. - public static object PtrToStructure(IntPtr lparam, Type cls) { - return Marshal.PtrToStructure(lparam, cls); - } - - /// - /// Generic PtrToStructure(T) - because Marshal.PtrToStructure(T) doesn't - /// seem to be available in our build environment. - /// - /// - /// - /// - public static T PtrToStructure(IntPtr lParam) - { - return (T)Marshal.PtrToStructure(lParam, typeof(T)); - } - // For some reason "StructureToPtr" requires super high permission. public static void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld) { diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs index 2441d78d39135e9df04a4a17f00a3c3cf181ee9b..a34e0540fd60fe1e8170d69416c24b2650005451 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs @@ -640,7 +640,7 @@ private static int[] ArrayFromIntPtr(IntPtr pInts, int cInts) // into something more managable. internal static AutomationEventArgs GetUiaEventArgs(IntPtr argsAddr) { - UiaEventArgs args = (UiaEventArgs)Marshal.PtrToStructure(argsAddr, typeof(UiaEventArgs)); + UiaEventArgs args = Marshal.PtrToStructure(argsAddr); AutomationEvent eventId = AutomationEvent.LookupById(args._eventId); if (eventId == null) @@ -658,7 +658,7 @@ internal static AutomationEventArgs GetUiaEventArgs(IntPtr argsAddr) case EventArgsType.PropertyChanged: { - UiaPropertyChangedEventArgs pcargs = (UiaPropertyChangedEventArgs)Marshal.PtrToStructure(argsAddr, typeof(UiaPropertyChangedEventArgs)); + UiaPropertyChangedEventArgs pcargs = Marshal.PtrToStructure(argsAddr); AutomationProperty propertyId = AutomationProperty.LookupById(pcargs._propertyId); if (propertyId == null) @@ -672,34 +672,34 @@ internal static AutomationEventArgs GetUiaEventArgs(IntPtr argsAddr) case EventArgsType.StructureChanged: { - UiaStructureChangedEventArgs scargs = (UiaStructureChangedEventArgs)Marshal.PtrToStructure(argsAddr, typeof(UiaStructureChangedEventArgs)); + UiaStructureChangedEventArgs scargs = Marshal.PtrToStructure(argsAddr); int[] runtimeId = ArrayFromIntPtr(scargs._pRuntimeId, scargs._cRuntimeIdLen); return new StructureChangedEventArgs(scargs._structureChangeType, runtimeId); } case EventArgsType.AsyncContentLoaded: { - UiaAsyncContentLoadedEventArgs aclargs = (UiaAsyncContentLoadedEventArgs)Marshal.PtrToStructure(argsAddr, typeof(UiaAsyncContentLoadedEventArgs)); + UiaAsyncContentLoadedEventArgs aclargs = Marshal.PtrToStructure(argsAddr); return new AsyncContentLoadedEventArgs(aclargs._asyncContentLoadedState, aclargs._percentComplete); } case EventArgsType.WindowClosed: { - UiaWindowClosedEventArgs wcargs = (UiaWindowClosedEventArgs)Marshal.PtrToStructure(argsAddr, typeof(UiaWindowClosedEventArgs)); + UiaWindowClosedEventArgs wcargs = Marshal.PtrToStructure(argsAddr); int[] runtimeId = ArrayFromIntPtr(wcargs._pRuntimeId, wcargs._cRuntimeIdLen); return new WindowClosedEventArgs(runtimeId); } case EventArgsType.Notification: { - UiaNotificationEventArgs nargs = (UiaNotificationEventArgs)Marshal.PtrToStructure(argsAddr, typeof(UiaNotificationEventArgs)); + UiaNotificationEventArgs nargs = Marshal.PtrToStructure(argsAddr); return new NotificationEventArgs(nargs._notificationKind, nargs._notificationProcessing, Marshal.PtrToStringUni(nargs._displayString), Marshal.PtrToStringUni(nargs._activityId)); } case EventArgsType.ActiveTextPositionChanged: { - UiaActiveTextPositionChangedEventArgs atpcargs = (UiaActiveTextPositionChangedEventArgs)Marshal.PtrToStructure(argsAddr, typeof(UiaActiveTextPositionChangedEventArgs)); + UiaActiveTextPositionChangedEventArgs atpcargs = Marshal.PtrToStructure(argsAddr); return new ActiveTextPositionChangedEventArgs(atpcargs._textRange); } }