Rakesh Simpi

hi there!


i am developing an application in which i need to let UI know about some events.. I've chosen windows messages to that for me.


this is how my code looks like.....

WCHAR* t = L"MyAppli";
HWND handle = FindWindow(NULL, t); //always succeeds in acquiring the window handle
LRESULT l = SendMessage(handle , 8686, 1, 1);
if(l==0)
{
DWORD er = GetLastError(); //always says error #87 Invalid Parameter
}

what could be the reason for this...



Re: Visual C++ General problem with PostMessage error #87

Ramkrishna Pawar

Is your application unicode I suspect a misuse of WCHAR string with ANSI version of FindWindow, if you want to keep your code portabl;e for unicode, you should use TCHAR * and not hardcoded wide char strings.

Code Block

TCHAR* t = _T("MyAppli");
HWND handle = FindWindow(NULL, t);


Another suggestion would be use all wide char version APIs with wide char strings

Code Block

WCHAR* t = L"MyAppli";
HWND handle = FindWindowW(NULL, t);

LRESULT l = SendMessageW(handle , 8686, 1, 1);






Re: Visual C++ General problem with PostMessage error #87

Rakesh Simpi

thanks ramakrishna for your reply..

but none of your suggestions seem to be working for me.... i am still getting same error..

let me tell you.. findwindow is giving me some non zero handle... and also i able to change window text through setwindowtextw for resultant window.


hence i am sure that there is nothing wrong in getting window handle. now can any of u tell me, what could be the cause of this error





Re: Visual C++ General problem with PostMessage error #87

Pintu Shukla

have a look on the Following code, What is this 8686 in your code.it's Always good if your Message Should have Proper Name

Code Block

TCHAR szClassName[] = _T("TestApp");
HWND hWnd = ::FindWindow(NULL, szClassName);
if(hWnd !=NULL)
{
LRESULT lReturn = ::SendMessage(hWnd , 8686, (WPARAM)1 , (LPARAM)1);

if(lReturn ==0)
{
DWORD er = GetLastError();
}
}



Thanx




Re: Visual C++ General problem with PostMessage error #87

Viorel.

According to MSDN documentation, it is not quite clear if GetLastError is applicable for SendMessage function (but works with PostMessage). Does your custom message actually achieve the target window and you handle this message





Re: Visual C++ General problem with PostMessage error #87

Pintu Shukla

I am sure if user is getting this Problem this is due to this 8686 . what is this because if i Modified your code little bit to check the above suggested code like

Code Block

TCHAR szClassName[] = _T("TestApp");
HWND hWnd = ::FindWindow(NULL, szClassName);
char *str = new char[255];
::GetWindowText(hWnd,str,255); //here str will also return TestApp

delete []str;

Second thing if you are getting some Error value in ::GetLastError() .That doesn't mean that this return code comes from :: SendMessage() Just Check out my Previous Example i am sure in ::GetLastError() Will return you zero. So if still some problem is there .that can be due to your Parameter of SendMessage() etc.

Thanx






Re: Visual C++ General problem with PostMessage error #87

Rakesh Simpi

no frirends,,,



none seem to be working out.... Tongue Tied


i have changed my code to:

#define _MESSAGE_HANDLER_CHANGED 0x8686

WCHAR* t = L"MyAppli";
HWND handle = FindWindowW(NULL, t);
SetLastError(0);
BOOL result= PostMessage(handle , _MESSAGE_HANDLER_CHANGED, (WPARAM)1, (LPARAM)1);
if(result==0) //always returns 0
{
DWORD er = GetLastError(); //always reads to be error #87
}




please help !





Re: Visual C++ General problem with PostMessage error #87

Pintu Shukla

What is this _MESSAGE_HANDLER_CHANGED . Do you want to implement some user defined function here . Have a look on my First Post and try Once again. and if _MESSAGE_HANDLER_CHANGED is a user defined function then use WM_USER and WM_APP macro.for more detail have a look in MSDN for user define function.

Thanx