Search code examples
vb.netwinapivb6window-handles

IsWindow returns false for existing window handle


In a VB6 application I am checking if a certain VB.NET WinForms window exists:

Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long

If Not IsWindow(102937) Then
      MessageBox("Window not found!")
End If

The messagebox is shown, but the window DOES exist.

I inspect it by

Debug.Print(Me.Handle.ToInt32)'it prints 102937

What goes wrong here? Am I perhaps handling the return value of "IsWindow" incorrectly?

Thank you.


Solution

  • I found the solution:

    I was indeed using the WinAPI function incorrectly.

    I should have used

    If IsWindow(102937) <> 1 Then