prog.c
We include
tchar.h because it defines
_tWinMain depending on
UNICODE to either
WinMain or
wWinMain. Thus, by declaring «our» WinMain as
_tWinMain, depending on
_UNICODE, either
WinMain or
wWinMain is called.
The program itself is rather simple: it shows a message box that reveals which entry point was used and what the size of a TCHAR is and how MessageBox is expanded.
#include <windows.h>
#include <tchar.h>
#include <strsafe.h>
#define macroToString(macro) expandMacro(macro)
#define expandMacro(macro) TEXT(#macro)
void msg(LPCTSTR calledFunction) {
TCHAR buf[500];
StringCbPrintf(buf, 500,
TEXT("Called function: %s\nSize of TCHAR = %d\nMessageBox = %s"),
calledFunction,
sizeof(TCHAR),
macroToString(MessageBox));
MessageBox(NULL,
buf,
GetCommandLine(),
0
);
}
WINAPI _tWinMain (
HINSTANCE hInstance ,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine ,
int nShowCmd
) {
msg(macroToString(_tWinMain));
return 0;
}
Makefile
This Makefile creates two versions of the program: ansi.exe and unicode.exe. unicode.exe is produced with _UNICODE and UNICODE defined.
all: unicode.exe ansi.exe
unicode.exe: unicode.obj
@link /nologo unicode.obj user32.lib /OUT:unicode.exe
ansi.exe: ansi.obj
@link /nologo ansi.obj user32.lib /OUT:ansi.exe
unicode.obj: prog.c Makefile
@cl /nologo /W3 /DUNICODE /D_UNICODE /c prog.c /Founicode.obj
ansi.obj: prog.c Makefile
@cl /nologo /W3 /c prog.c /Foansi.obj
clean:
@del *exe *.obj