用VC6進行UNICODE程式設計

2021-06-20 17:54:14 字數 1077 閱讀 4578

1. 新增 unicode 和 _unicode 預處理定義

位置:project settings -> c/c++ -> preprocessor definitions

新增了這兩個定義後,mfc的一些內建型別如 tchar、cstring 都將轉為支援寬字元型別(wchar_t)

2. 使用寬字元相關型別,如:

char -> tchar、char * -> lptstr、const char * -> lpctstr

3. 對字串常量使用 _t() 巨集

4. 替換c庫中的中字串操作函式,如 strlen -> _tcslen、strcmp -> _tcscmp 等

類似的還有c庫中字串與數字的轉換函式,如 atoi -> _ttoi、itoa -> _itot 等

5. 將 project settings -> link -> output -> entry point 設為 wwinmaincrtstartup

否則會有如下錯誤:

msvcrtd.lib(crtexew.obj) : error lnk2001: unresolved external symbol _winmain@16

6. c++標準庫中的string,有對應的寬字元版本wstring,兩者均為basic_string的特化版本

可在stdafx.h中:

#ifdef _unicode

#define tstring wstring

#else

#define tstring string

#endif

然後在**中使用 tstring 即可,類似的還有 fstream/wfstream、ofstream/wofstream 等

7. 寬字元版本的英文本元仍可直接與整型值進行比較,如:

cstring s = _t("abc");

assert(s[0] == 'a');

8. 對於仍需使用ansi字串的地方,如第三方類庫的介面,仍可繼續使用;如需進行unicode字串和ansi字串的互轉換,可使用 multibytetowidechar 和 widechartomultibyte

**:

用VC6進行UNICODE程式設計

1.新增 unicode 和 unicode 預處理定義 位置 project settings c c preprocessor definitions 新增了這兩個定義後,mfc的一些內建型別如 tchar cstring 都將轉為支援寬字元型別 wchar t char tchar char ...

VC6設定Unicode開發模式

1 將vc98 mfc lib下的mfc42u 手動拷貝到對應的安裝目錄下 2 為工程新增unicode和 unicode預處理選項 project settings c c preprocessor definitions,去除 mbcs,新增 unicode,unicode 3 設定程式入口點 ...

vc6 控制項

詳見msdn 為控制項新增乙個控制項型變數然後訪問之 edit idc edit1 m edit1 void ctest1dlg onbutton1 也可以直接使用id訪問 cstring str int i getdlgitemtextw idc edit1,str afxmessagebox s...