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(); }
main.cpp(9) : error C2731: 'WinMain' : function cannot be overloaded
main.cpp(8) : see declaration of 'WinMain'
Google didn't help in this case. Needless to say, neither did MSDN. This error occurs with both 2005 and 2008 versions.
Get rid of the main() function. That's for console, WinMain() is for gui app.
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; }
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.
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.
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.
Hey, profit isn't dumb!
Remember IBM's PS/2 and the proprietary bus interfaces? That was an attempt to lock in customers also.
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.
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...
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...
I happened across this from a thread on the cplusplus.com forums :
A bit more about windows string pointers.
I have counted 11 different type of string pointers in windows as follows;
...
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.
Thank god .net has a common type system
Thank god for .NET anyway, if only so we don't have to deal with winapi calls anymore.
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