Search code examples
c++windowswinapiwinmain

"APIENTRY _tWinMain" and "WINAPI WinMain" difference


What are the difference from these 2 function?:

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)

int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)

Solution

  • _tWinMain is just a #define shortcut in tchar.h to the appropriate version of WinMain.

    If _UNICODE is defined, then _tWinMain expands to wWinMain. Otherwise, _tWinMain is the same as WinMain.

    The relevant macro looks something like this (there's actually a lot of other code interspersed):

    #ifdef  _UNICODE
    #define _tWinMain  wWinMain
    #else
    #define _tWinMain  WinMain
    #endif