Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2731: 'wWinMain' : function cannot be overloaded

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.

like image 216
sashoalm Avatar asked Oct 30 '14 11:10

sashoalm


1 Answers

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.

like image 129
sashoalm Avatar answered Sep 22 '22 14:09

sashoalm