Quantcast
Viewing all articles
Browse latest Browse all 27209

[VB2010] SafeHandle

My goal is to set an EXTERNAL window as owner of a my form.

This simple code:
Code:

Dim OldParent As IntPtr

Form Load
OldParent = NativeMethods.SetWindowLong(Me.Handle, -8, ExtHwnd)

Form Closing
NativeMethods.SetWindowLong(Me.Handle, -8, OldParent)

works well and without any error......... but if I run the "code analysis" I get this error message:

" CA2006: Microsoft.Reliability: Control the use of 'FrmMain.OldParent', instance 'IntPtr' to determine whether it should be replaced with SafeHandle or CriticalHandle. "

Well, so what do I have to do????

I tryed to replace: Dim OldParent As System.Runtime.InteropServices.SafeHandle...

No errors, but SetWindowsLong returns a IntPtr, NOT a SafeHandle. :ehh:

I can't write "OldParent = CType( NativeMethods.SetWindowLong(Me.Handle, -8, ExtHwnd), System.Runtime.InteropServices.SafeHandle)

because I get error.

So how to replace PRATICALLY an IntPtr with a SafeHandle???? A SafeHandle IS NOT an IntPtr, and the API require IntPitr... :confused:

ty

Viewing all articles
Browse latest Browse all 27209

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>