I'm wondering why so many Win API functions are only defines to their real implemenation in MinGW.
Example:
MessageBox()
function as described in the MSDN documenation:
int WINAPI MessageBox(
_In_opt_ HWND hWnd,
_In_opt_ LPCTSTR lpText,
_In_opt_ LPCTSTR lpCaption,
_In_ UINT uType
);
And here's the implementation of MinGW (winuser.h
):
#define MessageBox MessageBoxA
/* ... */
WINUSERAPI int WINAPI MessageBoxA(HWND,LPCSTR,LPCSTR,UINT);
So MessageBox
is not a function, it's only a define for the real function.
Another one (taken from winbase.h
:
#define GetVersionEx GetVersionExA
/* ... */
WINBASEAPI BOOL WINAPI GetVersionExA(LPOSVERSIONINFOA);
As you can see in most cases the functions are implemented as macros to their real implementation.
Is there any reason for doing this? And why are they not implemented as "real" functions (using their real name)?
From GetVersionEx documentation:
Unicode and ANSI names:
GetVersionExW
(Unicode) andGetVersionExA
(ANSI)
From Conventions for Function Prototypes documentation:
The preprocessor expands the macro into either the Windows code page or Unicode function name. The letter
"A"
(ANSI) or"W"
(Unicode) is added at the end of the generic function name, as appropriate. The header file then provides two specific prototypes, one for Windows code pages and one for Unicode, as shown in the following examples.
In your case, GetVersionEx
will expand to GetVersionExA
because it looks like you are using Windows code page.
Using the DEFINE
s enable you to use the same code with difference compiler options. For example: MessageBox
will use MessageBoxW
if using unicode
, but MessageBoxA
if not. It would be a pain to have to go through an entire code base just to change the method names.
Edit: Also see Christoph's reference, which this answer is referring to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With