WindowInteropHelper.Handle — do I need to release

2019-03-06 07:09发布

In WPF I'm getting IntPtr handle using this code:

IntPtr mainWindowHandle = new WindowInteropHelper(Application.Current.MainWindow).Handle

When I finish using this handle, do I need to release it in anyway (e.g. using Marshal.FreeHGlobal() method) ?

EDIT: I was thinking about Marshal.FreeHGlobal(), not Marshal.Release(), sorry!

标签: wpf winapi com
1条回答
别忘想泡老子
2楼-- · 2019-03-06 08:09

This is not in any way related to COM, Marshal.Release() does not apply. You simply get a copy of the native window handle, it does not have to be released. You need to stop using the handle when the window is destroyed. Signaled by the Window.Close event.

查看更多
登录 后发表回答