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)

ここでこのコードを使用すると、次のようになります。

PRO_MAIN(argc, argv)
{
  ...
}

エラーが発生します:

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

どうしたの?

4

1 に答える 1

4

ルールに違反しました:二重アンダースコアは実装用に予約されています!(とりわけ。)

__main、、main__などは使用できませ_Mainん。他のものを選択する必要があります。

私はあなたがこの仕事をすることをお勧めします:

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

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

PRO_MAINこれには、Windows以外のアプリケーションの場合、単純に何も拡張できず、プログラムが標準のmain関数でコンパイルされるという追加の利点があります。これが私がすることです。

于 2012-04-25T03:44:31.013 に答える