Sign in to follow this  
AndOrXor

SendMessage() fails with Error 183

Recommended Posts

This makes no sense.. I have the following code:
bool val = SendMessage(hTargetApp, WM_KEYDOWN, VK_SPACE, 1);
if (!val) SysError("SendMessage_Space_Down");
The SysError function is a modified version of ErrorExit from MSDN:
void SysError(LPTSTR lpszFunction) 
{
    TCHAR szBuf[256]; 
    LPVOID lpMsgBuf;
    DWORD dw = GetLastError(); 

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    wsprintf(szBuf, 
        "%s failed with error %d: %s", 
        lpszFunction, dw, lpMsgBuf); 
 
    add_log(szBuf);
	
	LocalFree(lpMsgBuf);

	return;
}
And this is the result in the log:
SendMessage_Space_Down failed with error 183: Cannot create a file when that file already exists.
This makes no sense to me, because using SendMessage() has nothing to do with writing files. Also, it cannot be a problem the logging function, because as you can see, the SysError function traps the error right away, so the only thing it can be is SendMessage().

Share this post


Link to post
Share on other sites
SendMessage's return value is not a success or error code. It's depending on the message and can be anything.
Also, it's not a bool, but a LRESULT.

The return value could be 0 if the user processes WM_KEYDOWN, but could be anything else as well.
The only thing you can tell from a returned value, that the target app processed the message. If it didn't you would get stuck in SendMessage.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this