Tech Support > Microsoft Windows > Development Resources > Functions with an A on the end of the name
Functions with an A on the end of the name
Posted by Bruce Varley on March 24th, 2007


Hi, This newsgroup has been more than good to me, and I'm working hard to
solve my problems on my own. But this one I could really use a bit of help
on, I've been bitten so many times by it.

What on earth are the functions with an A on the end, such as PostMessageA,
MessageBoxA? When I put a PostMessage() statement in a global function, the
compiler give the error below. However, PostMessageA doesn't even show in
the MSDN searches, it isn't anywhere that I can find in the function
documentation, and even googling on it provides very scant information. It
would be very nice if I knew where to go to find out what the arguments for
these elusive functions are. If anyone could provide a pointer on where to
look, it would be very much appreciated.

error C2660: 'PostMessageA' : function does not take 3 parameters


Posted by Leslie Milburn on March 24th, 2007



"Bruce Varley" <bxvarley@weastnet.com.au> wrote in message
news:4604c1ef@quokka.wn.com.au...
To cater for both ASCII and Unicode two versions of some functions exist
ending in an A and a W. A #define is then created which chooses one of them
depending upon whether or not UNICODE has been defined.

So if you are getting a PostMessageA error then that means the compiler
thinks the build is non-unicode and so uses PostMessageA().

At the end of the day, the problem is that basically you do not have the
correct number of parameters in the function call.

Leslie.



Posted by Scott McPhillips [MVP] on March 24th, 2007


Bruce Varley wrote:
You have two unrelated issues here. Windows API functions are provided
in two versions, with an 'A' or a 'W' at the end of the name. If your
program is built to use UNICODE your calls to PostMessage are translated
into calls to PostMessageW. If not a unicode build your calls are
translated to PostMessageA. (W is for Wide, A is for ASCII.) The
difference is that a UNICODE build requires 16 bit characters for text,
otherwise 8 bit chars are used. In all cases, the 'A' and 'W' versions
of API functions take the same number of parameters.

The "does not take 3 parameters" error arises due to confusion between
API functions and MFC functions that have the same name. The MFC
PostMessage function takes 3 parameters, and to call it you must be in a
CWnd member function or use a CWnd reference or pointer:

pWnd->PostMessage(msg, w, l);

The API PostMessage function is at global scope and requires 4 parameters.

PostMessage(hwnd, msg, w, l);

You said you are calling PostMessage from a global function, so the
compiler interprets this as a call to the global-scope API function.
I.e. you didn't provide a CWnd reference or pointer to specify where to
post the message to.

--
Scott McPhillips [VC++ MVP]


Posted by JussiJ on March 26th, 2007


If you look at the Win32 headers you will see this:

WINUSERAPI BOOL WINAPI
PostMessageA(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam);

WINUSERAPI BOOL WINAPI
PostMessageW(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam);

#ifdef UNICODE
#define PostMessage PostMessageW
#else
#define PostMessage PostMessageA
#endif // !UNICODE

So as this shows, depending on the value of UNICODE PostMessage
can be defined as PostMessageW or PostMessageA.

Just think of PostMessageA or PostMessageW as just PostMessage.

See the definitions shown above.

As shown above, PostMessage takes 4 arguments not 3

Jussi Jumppanen
Author: Zeus for Windows IDE - Ultimate programmer's editor
http://www.zeusedit.com



Similar Posts