sendmessage() returns 0

burpicane

New member
Joined
Jan 18, 2009
Messages
3
Programming Experience
Beginner
Hello
I'm having a problem with my program that is sending a key to a window of a game based on the q3 engine. The problem is sendmessage() returns 0 which menas that it failed. So I retrieved the error which is 1400 which belongs to INVALID_WINDOW_HANDLE.
But I'm 99,9999999% sure the window handle is right.... I once printed it to the console and checked it with a program which shows all windows and their hwnd and it matched.

I'll supply the source:

Declaration of functions
VB.NET:
    Public Declare Auto Function FindWindow Lib "user32.dll" _
        Alias "FindWindow" (ByVal lpClassName As String, _
                            ByVal lpWindowName As String) As IntPtr
Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal Msg As IntPtr, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

Declaration of hwnd
VB.NET:
Public hwnd As IntPtr
hwnd = FindWindow("SoF2 MP", "SoF2 MP")

the sendmessage() use
VB.NET:
        SendMessage(hwnd, &H100, &H6D, &H4A0001)
        SendMessage(hwnd, &H101, &H6D, &HC04A0001)

Anyone that might have an idea why it comes with this INVALID_WINDOW_HANDLE....
 
&H100 will be meaningless to 99,9999999% of programmers, but if you say WM_KEYDOWN message then 99,9999999% will know what you mean. Define the constants that represent the message values and use the constant variables when you are calling WinAPI functions.

A INVALID_WINDOW_HANDLE error could indicate FindWindow didn't find your window and returned NULL.

(About "q3", I don't know it.)
 
ah q3 I should have spelled Quake 3.... (Games as counter strike etc) but that doesn't really matter...

You true about my lazyness that I should have used wm_keydown etc I will change it right now so the code is more readable ;)

It does find a window.. It checks the value for the hwnd and it just gives a valid number. So it is not returning NULL thats what it makes so strange for me

EDIT: After not using the FindWindow function but using the MainWindowHandle from a process I managed to get rid of the INVALID_WINDOW_HANDLE and the function is working now. I have no idea why FindWindow() gave a wrong value but ok its works I'm happy
 
Last edited:
Back
Top