在Visual Studio 2010中将控制台项目转换/移植到无形应用程序

Converting/Porting Console Project to Formless App in Visual Studio 2010

本文关键字:应用程序 无形 转换 项目 Studio Visual 2010 控制台      更新时间:2023-10-16

我对 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(/SUBSYSTEM:WINDOWS)。然后,我将项目设置中的入口点更改为ext_main。我还必须确保函数获得CMDCommandLine,因为APP需要读取参数。

谢谢你的帮助。

使用 WinMain

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

并将Project Properties -> Linker -> Advanced -> Entry Point上的入口点设置为 WinMain .

还有/SUBSYSTEM:WINDOWS,但你已经这样做了。