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

时间:2012-10-06 23:35:06

标签: c++ visual-studio-2010

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

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

使用WinMain

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

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

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