PDA

View Full Version : Findwindow failing in vb.net


MultiThread
17th April 2002, 19:25
I ported the beginner code in the winamp dev area to vb.net and it seems to have a problem when trying to find the winamp handle. The following segment may be enough for someone to see my problem:

option strict off
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public hWndWinAMP As Long
...
hWndWinAMP = FindWindow("Winamp v1.x", vbNullString)

hWndWinAMP is equaling a very high number, probably not right:
419116244617397430

doesn't seem right and no SendMessages will work with that handle.

Anyone try .net yet?

baafie
22nd April 2002, 19:12
I tried the Process function in the .NET Framework using C#. They work SOMETIMES. 4 Out of 5 times it does the job, but sometimes it just doesn't. I can't explain it.
BTW I haven't used VB much, can't help you with the code.
Maybe you need some of them [DllImport("User32.dll")] statements(look in MSDN .NET)

MultiThread
22nd April 2002, 20:23
Thanks for the reply, and yes you are correct - I had to add the statement you mentioned, plus ".net-ize" the code to get it to work over the weekend:

<DllImport("user32.dll")> Public Shared Function _
FindWindow(ByVal strClassName As String, ByVal strWindowName As String) As Integer
End Function

Public Function WinAMP_GetHandle() As Boolean
WinAMP_GetHandle = True
Try
m_hwnd = FindWindow("Winamp v1.x", Nothing)
If m_hwnd = 0 Then
WinAMP_GetHandle = False
End If
Catch
WinAMP_GetHandle = False
End Try

End Function

thanks!