Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

c++ - wWinmain, Unicode, and Mingw

I am working on learning the windows API and am using mingw as my compiler with Code::Blocks as my IDE. I have run into an issue with using the wWinMain function. I used the program located here link text. It compiles fine on VSC++ 2008 express but when using mingw i get the "undefined reference to WinMain@16" error. I have figured out what the problem is (i think). By replacing the wWinMain with just Winmain and the String pointer PWSTR with LPSTR it compiles perfectly. My question is, how can i fix this, and if not, is not using Unicode that big of a deal.

Thanks.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For old versions of MinGW, you can use a wrapper:

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.


For new versions of MinGW, you should use the -municode option, like it says in the mingw-unicode-main readme:

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).

The -municode option works with MinGW-w64. In 2012-07, when I tried MinGW, it did not have the -municode option.

Here is how to install MinGW-w64:

Target Win32:

Target Win64:


Unicode-related questions:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...