1

我对 C/C++ 知之甚少,但我想将 C++ 控制台项目编译为常规 Windows 应用程序。所以最后应用程序根本没有表单,只执行代码。这是我从 ufasoft 矿工那里得到的代码:

/*###########################################################################################################################
# Copyright (c) 1997-2012 Ufasoft   http://ufasoft.com   mailto:support@ufasoft.com                                         #
#                                                                                                                           #
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 3, or (at your option) any later version.                    #                                                          #
#                                                                                                                           #
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied        #
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.     #
#                                                                                                                           #
# You should have received a copy of the GNU General Public License along with this program;                                #
# If not, see <http://www.gnu.org/licenses/>                                                                                #
###########################################################################################################################*/

#include <el/ext.h>

using namespace Ext;

#undef main
#undef wmain

extern "C" int __cdecl _my_wmain(int argc, wchar_t *argv[], wchar_t *envp[]);
extern "C" int __cdecl _my_main(int argc, char *argv[], char *envp[]);


int _cdecl ext_main(int argc, argv_char_t *argv[], argv_char_t *envp[]) {
#if UCFG_WCE
    RegistryKey(HKEY_LOCAL_MACHINE, "Drivers\\Console").SetValue("OutputTo", 0);
#endif

    atexit(MainOnExit);

#if UCFG_ARGV_UNICODE
    return _my_wmain(argc, argv, envp);
#else
    return _my_main(argc, argv, envp);
#endif
}

#if UCFG_WCE
#   if UCFG_ARGV_UNICODE
#       pragma comment(linker, "/ENTRY:mainWCRTStartup")
#   else
#       pragma comment(linker, "/ENTRY:mainACRTStartup")
#   endif
#endif

如何将其转换为常规的 Windows 应用程序?我已经将子系统更改为 Windows (/SUBSYSTEM:WINDOWS)。然后我把ProjectSettings中的EntryPoint改成了ext_main。我还必须确保函数获取 CMDCommandLine 导致 APP 需要读取参数。

谢谢您的帮助。

4

1 回答 1

1

使用WinMain

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    return 0;
}

并将入口点设置Project Properties -> Linker -> Advanced -> Entry PointWinMain.

而且/SUBSYSTEM:WINDOWS,但你已经这样做了。

于 2012-10-06T23:47:31.507 回答