PostMessage and syntaxe errors
I experience a very strange behavior of my compilator. The messages it gives me are not really explicit.
Why with :
HANDLE hMainWnd = theApp.GetMainWnd()->m_hWnd;
PostMessage(hMainWnd, WM_MYMESSAGE, 3, 4);
do I get those errors ?
error C2143: syntax error : missing ')' before ';'
error C2660: 'PostMessageA' : function does not take 2 parameters
error C2143: syntax error : missing ';' before ','
error C2059: syntax error : ')'
All those error for the same line, the one where PostMessage is. It does not depend on any other line, because when I move it, the error line number changes too.
PostMessage has for sure 4 parameters. I forst tried with casting the last arguments to WPARAM and LPARAM, but then I thought it might got confused by the (). Where is the trick here?
and maybe ...
What file should be included in #include to use PostMessage properly?
thanks
Marina
# 1 Re: PostMessage and syntaxe errors
I can't say I know what the problem is here, but try putting "::" in front of "PostMessage". If that doesn't help things at all you could always try ::SendMessage if that would suit your purpose also..
-Cube01
cube01 at 2007-11-10 5:41:22 >

# 2 Re: PostMessage and syntaxe errors
::PostMessage does not change anything.
And I want to use PostMessage. I might have to use SendMessage at other places, but they don't do exactly the same thing.
SendMessage force to react to the message it sends directly, while PostMessage puts it in the queue with the others and will be treated at its time.
Thanks.
Marina
# 3 Re: PostMessage and syntaxe errors
Putting a :: before the PostMessage() works as i have just tried it on a dialog based application
e.g. ::PostMessage(m_hWnd,WM_MYMSG,4,3);
If you dont put the :: you'll get the error that you got.
Perhaps you could try including windows.h
SalimS at 2007-11-10 5:43:19 >

# 4 Re: PostMessage and syntaxe errors
No it does not change anything.
I'm calling it from a function that has nothing to do with anything else, that's my thread creation function. The one called by CreateThread somewhere else.
Does that help finding what is wrong?
# 5 Re: PostMessage and syntaxe errors
Try this: CWnd* pMain=AfxGetMainWnd();
if (pMain!=NULL)
pMain->PostMessage(WM_MYMESSAGE,3,4);
If you still get that error, then maybe you should take a look on your code before these lines.
-J-
____________________________________________
Feedback (or ratings) on answers will be appreciated. (I just want to know if I was useful...)
-J- at 2007-11-10 5:45:23 >

# 6 Re: PostMessage and syntaxe errors
DWORD WINAPI RunThreadCom(LPVOID lpParameter)
{
CWnd* pMain=AfxGetMainWnd();
if (pMain!=NULL)
pMain->PostMessage(WM_EDWINMESSAGE,3,4);
return STATUS_OK;
}
I reduced to the minimum in this function. I don't get the error message about PostMessageA, with 2 parameters.
But still those syntax errors on the PostMessage line.
# 7 Re: PostMessage and syntaxe errors
I can't replicate you're errors when i try the same code in a dialog based application i get no errors.
SalimS at 2007-11-10 5:47:24 >

# 8 Re: PostMessage and syntaxe errors
Hmmm, I think this fn is ok and the error is from other parantheses or brackets that were not closed right. Somewhere else in the code...
I'm afraid the only thing you can do is to comment this function and maybe others and to find the bad line.
I think also looking in MSDN for C2143 and C2059 should help.
-J-
____________________________________________
Feedback (or ratings) on answers will be appreciated. (I just want to know if I was useful...)
-J- at 2007-11-10 5:48:27 >

# 9 Re: PostMessage and syntaxe errors
I know sometimes I ask stupid questions.
But I have checked where the syntax error could be.
If my function has only a return statement, it compiles ok.
It appears when I write the PostMessage line.
I can't say it otherwise, that's completely weird.
I rebuilt the whole project too...
Ok, this time I close VC++ and retry. But I copied the function as it is, it is the only one in my file, and before it, you have
// ComThread.cpp
// This file describe the communication thread.
#include "stdafx.h"
#include "loading.h"
#include "../edwindlg.h"
#include "../edwin1.h"
#include "windows.h"
extern CEdwinApp theApp;
# 10 Re: PostMessage and syntaxe errors
I restarted VC++...
I'm really fed up with this stupid error... there must be something ...
# 11 Re: PostMessage and syntaxe errors
Where are you making this call? There are three PostMessage functions.
The SDK function (preceeded by double colon) requires 4 args.
The CWindow function requires 4 args.
In both above cases the first arg is the window handle.
The CWnd function requires 3 arguments.
The first arg of that function is the message itself.
If the class in which you are calling this is derived from CWnd
(such as CView or a CView derived class, or CFrameWnd, or CMDIFrameWnd)
you should not pass the window handle.
# 12 Re: PostMessage and syntaxe errors
Hi Marina,
please have a look at your definition of WM_MYMESSAGE,
maybe you have put a semicolon after your #define, like this :
#define WM_MYMESSAGE WM_APP+10;
I made this mistake before, so maybe you made it too ?
And check your parenthesis here if you've put some.
meynaf at 2007-11-10 5:52:30 >

# 13 Re: PostMessage and syntaxe errors
Yes that was it :-)
You guessed right, I found it quite late...
I hate these kind of stupid errors.
Thanks.
Marina