关于c ++:wWinmain,Unicode和Mingw

wWinmain, Unicode, and Mingw

我正在学习Windows API,并使用mingw作为我的编译器,并使用Code :: Blocks作为我的IDE。 我在使用wWinMain函数时遇到问题。 我使用了位于此处的程序链接文本。 它在VSC ++ 2008 Express上编译良好,但是使用mingw时出现"未定义引用WinMain @ 16"错误。 我已经弄清楚了问题所在(我认为)。 通过仅用Winmain替换wWinMain以及用LPSTR替换字符串指针PWSTR,它可以完美地编译。 我的问题是,我该如何解决这个问题,如果不能解决,那就不是使用Unicode了。

谢谢。


对于MinGW的旧版本,您可以使用包装器:

mingw-unicode-main:

https://github.com/coderforlife/mingw-unicode-main/

Simple wrappers to add wmain and wWinMain support in MinGW

These wrappers allow for use of wmain / wWinMain in MinGW seamlessly
with Unicode (WCHAR), regular (CHAR), or the ability to choose
(TCHAR).

The instructions for using them are in the files. Also take a look at
other programs that use them.

对于新版本的MinGW,应使用-municode选项,如mingw-unicode-main自述文件中所述:

Note: This should no longer be used as MinGW now has a built-in
solution. Add -municode to the command line (and possibly extern"C"
to the wmain function).

-municode选项可与MinGW-w64一起使用。在2012-07年,当我尝试使用MinGW时,它没有-municode选项。

这是如何安装MinGW-w64:

目标Win32:

  • 主页>针对Win32的工具链>个人构建> rubenvb> gcc-4.7-release:

    http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-4.7-release/

  • 在Windows上,您需要" i686-w64-mingw32-gcc-4.7.2-release-win32_rubenvb.7z"。

  • 将文件夹解压缩到驱动器的根目录。

  • 将" mingw32"文件夹重命名为" MinGW-32"。

目标Win64:

  • 主页>针对Win64的工具链>个人构建> rubenvb> gcc-4.7-release:

    http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/gcc-4.7-release/

  • 在Windows上,您需要" x86_64-w64-mingw32-gcc-4.7.2-release-win32_rubenvb.7z"。

  • 将文件夹解压缩到驱动器的根目录。

  • 将" mingw64"文件夹重命名为" MinGW-64"。

与Unicode相关的问题:

  • 如何在Code :: Blocks中使用wmain()入口点?
  • 在Dev-C ++中编译Windows程序会出现错误
  • #define _UNICODE无法与MinGW + CodeBlocks配合使用


使用普通的(非unicode)WinMain函数,然后使用GetCommandLineW获取unicode命令行。 MinGW不了解wWinMain

您可能会发现在MinGW上进行工作很困难;上次使用它时,它不支持C ++标准库的大多数wchar_t组件(即std::wifstreamstd::wstring等),这使得与Unicode Windows位的连接变得困难。

您有反对MSVC的东西吗?


我知道我应该发表评论而不是回答,但是我没有足够的声誉。

我想补充一点,我必须在[设置>编译器...>工具链可执行文件>程序文件]中更改exe文件的链接,以便运行社区版本。

同样,我从2016年开始使用CodeBlocks声称它是Unicode,但是-municode选项不起作用,只有对Community进行的MiniGW更新才起作用。

如果要再次使用main而不是wmain,则必须删除-municode选项。