WindowNative.GetWindowHandle no longer returns valid hWnd #18775
BertrandDeSaintBezier
started this conversation in
General
Replies: 1 comment
-
Thanks for the question. To be sure, which target framework are you debugging with? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are trying to embed a Win32 window in a Uno application as a User Control. In previous versions of Uno (5.1.80, for example, see attached screenshot) this worked fine, where the following method :
WinRT.Interop.WindowNative.GetWindowHandle(object)
would return a validWindow Handle Id
, which could be attached to the Uno process usingnint SetParent(nint child, nint parent)
.Uno WinUI : 5.1.80
It seems like in the newer Uno SDK, this same method doesn't seem to return a coherent Window Handle (see attached screenshot in version 5.5.32), and we are unable to hook the Win32 process to Uno. It appears that the implementation of
GetWindowHandle
has changed to :return new IntPtr((long)window.AppWindow.Id.Value);
Uno.Sdk: 5.5.32
We found this ongoing discussion on the WinAppSDK repo and figured that maybe we could use the
Win32Interop.GetWindowFromWindowId(appWindow.Id)
method to get the Id, but we don't have access to the Win32Interop class.Not sure if this is a recent Uno implementation change or something to do with WinAppSDK, but we have found a workaround using Reflection, where we are brute-forcing our way to the window's hWnd Id.
Thought we would mention this in case it was a bug, and to help anyone else that has been running into a similar issue.
Cheers :)
Beta Was this translation helpful? Give feedback.
All reactions