![]() |
|
[WIN32] 'WinMain' : function cannot be overloaded |
Steve++
Member #1,816
January 2002
|
Using Visual C++ Express, I created an empty win32 project (not console) and created the following as main.cpp: #include <windows.h> int main() { return 0; } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { return main(); }
Compiler said:
main.cpp(9) : error C2731: 'WinMain' : function cannot be overloaded Google didn't help in this case. Needless to say, neither did MSDN. This error occurs with both 2005 and 2008 versions. |
Roy Underthump
Member #10,398
November 2008
![]() |
Get rid of the main() function. That's for console, WinMain() is for gui app. I love America -- I love the rights we used to have |
Steve++
Member #1,816
January 2002
|
Roy, I'll dumb it down for you. The following code also produces a C2731: #include <windows.h> int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { return 0; }
|
Roy Underthump
Member #10,398
November 2008
![]() |
When I tried the IDE in the Express versions, I couldn't create a gui app at all. I thought it was to avoid cutting into the sales of the $$$ versions. I just use makefiles. I love America -- I love the rights we used to have |
Steve++
Member #1,816
January 2002
|
It's not that hard to make a GUI app in Win32. Even easier with .NET WinForms. I found the problem... I was using LPTSTR instead of LPSTR. The reason I have a main() method called by WinMain is because I'm making a "magic main" system similar to that of Allegro, except simplified for my purposes. I'm actually using it in Ogre and Irrlicht, both of which I'm currently evaluating. |
axilmar
Member #1,204
April 2001
|
The only reason Microsoft did not use the regular main as the entry symbol of a C application is marketing: they feared that their code will be easily portable to other platforms. This generated hundreds of 'magic main' implementations and lots of boilerplate code to set things straight. It was one of the dumbest things ever to be done by a software company. |
Steve++
Member #1,816
January 2002
|
Hey, profit isn't dumb! |
Roy Underthump
Member #10,398
November 2008
![]() |
Remember IBM's PS/2 and the proprietary bus interfaces? That was an attempt to lock in customers also. I love America -- I love the rights we used to have |
torhu
Member #2,727
September 2002
![]() |
You don't need winmain. You can just set SubSystem to Windows in msvc. Then you have to set the entry point to mainCRTStartup. Both are in the linker setting in project properties. |
Neil Walker
Member #210
April 2000
![]() |
Quote: I found the problem... I was using LPTSTR instead of LPSTR. When I create a windows app I always use LPTSTR and not LPSTR. Mind you, I always let MSVC set up my startup code... Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Steve++ said: I found the problem... I was using LPTSTR instead of LPSTR.
Neil Walker said: When I create a windows app I always use LPTSTR and not LPSTR. Mind you, I always let MSVC set up my startup code... I happened across this from a thread on the cplusplus.com forums : guestgulkan's reply said:
A bit more about windows string pointers. ... LPTSTR //LPWSTR if UNICODE defined, LPSTR if UNICODE not defined I don't know if that's accurate or not, but maybe it has something to do with it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Neil Walker
Member #210
April 2000
![]() |
Thank god .net has a common type system Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Tobias Dammers
Member #2,604
August 2002
![]() |
Thank god for .NET anyway, if only so we don't have to deal with winapi calls anymore. --- |
Don Freeman
Member #5,110
October 2004
![]() |
There is a way to get Visual Studio Express to create Win32 Gui apps. Google it, or use the 2008 version that has it enabled by default.:P -- |
|