求助:为什么在VC中预定义了_UNICODE宏,就要自己写WINMAIN函数

winstonch 2004-10-17 08:40:56
为什么在VC中预定义了_UNICODE宏,就要自己写WINMAIN函数
...全文
176 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
winstonch 2004-10-17
  • 打赏
  • 举报
回复
THANK YOU PigKing(猪皇)
PigKing 2004-10-17
  • 打赏
  • 举报
回复
Unicode Programming Summary
Home | Unicode Tasks | Multibyte Character Set (MBCS) Tasks

To take advantage of the MFC and C run-time support for Unicode, you need to:

Define _UNICODE.
Define the symbol _UNICODE before you build your program.

Specify entry point.
In the Output category of the Link tab in the Project Settings dialog box, set the Entry Point Symbol to wWinMainCRTStartup.

Use “portable” run-time functions and types.
Use the proper C run-time functions for Unicode string handling. You can use the wcs family of functions, but you may prefer the fully “portable” (internationally enabled) _TCHAR macros. These macros are all prefixed with _tcs; they substitute, one for one, for the str family of functions. These functions are described in detail in the Internationalization section of the Run-Time Library Reference. For more information, see Generic-Text Mappings in TCHAR.H.

Use _TCHAR and the related portable data types described in Support for Unicode.

Handle literal strings properly.
The Visual C++ compiler interprets a literal string coded as

L"this is a literal string"

to mean a string of Unicode characters. You can use the same prefix for literal characters. Use the _T macro to code literal strings generically, so they compile as Unicode strings under Unicode or as ANSI strings (including MBCS) without Unicode. For example, instead of:

pWnd->SetWindowText( “Hello” );

use:

pWnd->SetWindowText( _T(“Hello”) );

With _UNICODE defined, _T translates the literal string to the L-prefixed form; otherwise, _T translates the string without the L prefix.

Tip The _T macro is identical to the _TEXT macro.

Be careful passing string lengths to functions.
Some functions want the number of characters in a string; others want the number of bytes. For example, if _UNICODE is defined, the following call to a CArchive object will not work (str is a CString):

archive.Write( str, str.GetLength( ) ); // invalid

In a Unicode application, the length gives you the number of characters but not the correct number of bytes, since each character is two bytes wide. Instead, you must use:

archive.Write( str, str.GetLength( ) * sizeof( _TCHAR ) ); // valid

which specifies the correct number of bytes to write.

However, MFC member functions that are character-oriented, rather than byte-oriented, work without this extra coding:

pDC->TextOut( str, str.GetLength( ) );

CDC::TextOut takes a number of characters, not a number of bytes.

To summarize, MFC and the run-time library provide the following support for Unicode programming under Windows NT:

Except for database class member functions, all MFC functions are Unicode-enabled, including CString. CString also provides Unicode/ANSI conversion functions.


The run-time library supplies Unicode versions of all string-handling functions. (The run-time library also supplies “portable” versions suitable for Unicode or for MBCS. These are the _tcs macros.)


TCHAR.H supplies portable data types and the _T macro for translating literal strings and characters. See Generic-Text Mappings in TCHAR.H.


The run-time library provides a wide-character version of main. Use wmain to make your application “Unicode-aware.”

--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
PigKing 2004-10-17
  • 打赏
  • 举报
回复
在project的setting中把入口点改为wWinMainCRTStartup
winstonch 2004-10-17
  • 打赏
  • 举报
回复
随便生成一个MFC应用程序,将setting中的预定义宏_MBCS改为_UNICODE看看
winstonch 2004-10-17
  • 打赏
  • 举报
回复
我现在就在被这个事情困扰着呢
薛定谔之死猫 2004-10-17
  • 打赏
  • 举报
回复
不会啊
PigKing 2004-10-17
  • 打赏
  • 举报
回复
谁说的?

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧