2
/** converts 'WinMain' to the traditional 'main' entrypoint **/
#define PRO_MAIN(argc, argv)\
    int __main (int, LPWSTR*, HINSTANCE, int);\
    int WINAPI WinMain (HINSTANCE __hInstance, HINSTANCE __hPrevInstance, \
                       LPSTR __szCmdLine, int __nCmdShow)\
    {\
        int nArgs;\
        LPWSTR* szArgvW = CommandLineToArgvW (GetCommandLineW(), &nArgs);\
        assert (szArgvW != NULL);\
        return __main (nArgs, szArgvW, __hInstance, __nCmdShow);\
    }\
    \
    int __main (int __argc, LPWSTR* __argv, HINSTANCE __hInstance, int __nCmdShow)

Now, when I use this code here:

PRO_MAIN(argc, argv)
{
  ...
}

I get the error:

error: conflicting types for '__main'
note: previous declaration of '__main' was here

What's the problem?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
ApprenticeHacker
  • 21,351
  • 27
  • 103
  • 153
  • What location information was associated with the "note:" line? Also, did you consider what the note is telling you? – geekosaur Apr 25 '12 at 03:47
  • 1
    You also could just not bother with `WinMain` entirely, use `main`, and explicitly tell the linker that you want a `SUBSYSTEM:WINDOWS` program. – jamesdlin Apr 25 '12 at 03:51
  • @jamesdlin thanks. Though irrelevant to the question, this pretty much solves all the problems of my project. But won't I run into any problems? – ApprenticeHacker Apr 25 '12 at 04:07
  • @IntermediateHacker: I'm not aware of any. – jamesdlin Apr 25 '12 at 04:24

1 Answers1

4

You have broken the rules: double-underscores are reserved for implementation! (Among other things.)

You simply cannot use __main, main__, _Main, etc. You should pick something else.

I would recommend you make this work:

int main(int argc, char* argv[])
{
    // main like normal
}

// defines WinMain, eventually makes call to main()
PRO_MAIN;

Which has the added advantage that for non-Windows applications, PRO_MAIN can simply expand to nothing, and the program still compiles with the standard main function. This is what I do.

Community
  • 1
  • 1
GManNickG
  • 494,350
  • 52
  • 494
  • 543