error C2731: 'wWinMain' : function cannot be overloaded

16,866

Solution 1

Thanks everyone, I finally found the real culprit, it's a typo, I use LPSTR lpCmdLine instead of LPTSTR lpCmdLine. The real mystery is why it compiled at all under VC6 - it did use wWinMain, but somehow it was OK for lpCmdLine to be char * instead of WCHAR *.

Now I changed it to:

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

And it works under VS2008 too.

Edit: I successfully compiled and even ran the program with this function definition under VC6:

int APIENTRY wWinMain(int *hInstance, float hPrevInstance, int *lpCmdLine, float nCmdShow)
{
    MessageBox(0,L"Running.",0,0);
    return 0;
}

Interestingly, replacing float nCmdShow to double nCmdShow does give a linker error, I assume because float is 32-bits but double is not.

Solution 2

For me it worked after changing WinMain to wWinMain in VS 2019

Share:
16,866
sashoalm
Author by

sashoalm

Updated on June 24, 2022

Comments

  • sashoalm
    sashoalm almost 2 years

    I upgraded an old project from VC6 to VS2008, and now I get this compile error:

    error C2731: 'wWinMain' : function cannot be overloaded
    

    At these lines of code:

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

    The same project compiles fine under VC6.