[WIN32] 'WinMain' : function cannot be overloaded
Steve++

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
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.

Roy Underthump

Get rid of the main() function. That's for console, WinMain() is for gui app.

Steve++

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

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.

Steve++

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

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++

Hey, profit isn't dumb!

Roy Underthump

Remember IBM's PS/2 and the proprietary bus interfaces? That was an attempt to lock in customers also.

torhu

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
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...

Edgar Reynaldo
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.
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.

Neil Walker

Thank god .net has a common type system ;)

Tobias Dammers

Thank god for .NET anyway, if only so we don't have to deal with winapi calls anymore.

Don Freeman

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

Thread #598938. Printed from Allegro.cc