making an api call error 126 (findWindow)

I'm trying to get a handle to a window, so I need to make an call to the api to the findwindow function..

so I declare:

DeclareFunction FindWindowLib "User32"Alias "FindWindowA" _

(ByVal lpClassNameAsString,ByVal lpWindowNameAsString)AsLong

Public WinWndAsLong


and make the call inside a sub:

Dim windowNameAsString

windowName = "Title"


WinWnd = FindWindow(vbNullString, windowName)

WinWnd gets trash, end the error variable is set to 126, wich means specific module not loaded
I tried to put the auto keyword, not sure what it means but I saw it on an example on making api call in msn website (waltrough to making api call in vb.net or something like) but it instead of giving 126 he gives 127 error #

What I am trying to accomplish is to get the window handle from it's name, what I need is to detect if the user pressed ctrl in other window than the app I'm working, so I need to set up a hook

any other way to get the window handle?

thanks in advance
marcel

[2253 byte] By [punk] at [2007-12-16]
# 1
forgot to mention, I'm using Visua Studio 7.1
punk at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Take a look here:
http://pinvoke.net/default.aspx/user32/FindWindow.html

Regards,
Vikram

Vikram at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
thanks, no error now, the problem might be elsewhere or not...
the difference was just in the declaration of findwindow
the error number after calling findwindow is 0

the value of the handle returned byt window appears to be trash, a very high number.. but
when testing the handle with :

Const SW_SHOWNORMAL = 1
Public
WinWnd As New IntPtr(0)
Declare
Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, _

ByVal lpWindowName As String) As IntPtr
Declare
Function ShowWindow Lib "User32" (ByVal Hwnd As IntPtr, _

ByVal nCmdShow As Long) As Long

'the original Hwnd was long, but I changed to IntPtr because of the declaration of findWindow

and call it as:

WinWnd = FindWindow(vbNullString, windowName)
ShowWindow(WinWnd, SW_SHOWNORMAL)

error # is 0, but nothing happens, also the value returned by showWindow looks like trash..

thanks again
marcel

punk at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
sorry, my mistake..
findWindow now returns 127 instead of 126... the difference I think is the auto
punk at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
other issue.. if I pass window name that doesn't exist no error codes and the function returns 0 properly..
punk at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
sorry for the bunch of replies, I'm still working with the code..

I was testing with a window called test.txt - Notepad

looks like the problem is with the .
if I rename the file just for test it woks.. but just for the first time, if I try to run it again it doesn't work, I have to close and open my app

anyway, I got it working by calling

AppActivate(windowName)

just before ShowWindow since AppActive doesn't works properly sometimes..

now I have to hook the keyboard, I'll just create another thread...

punk at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...