日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

VC++关于UNICODE版本的开发

發布時間:2023/11/27 生活经验 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VC++关于UNICODE版本的开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

關于UNICODE版本的開發

  1. 代碼轉換方案

    1. 概述

在VC6.0中,相應的有一些宏來代替ANSI的函數、宏或數據類型,這些宏在ANSI編譯條件中處理字符串為單字節,而在UNICODE中處理字符串為雙字節,請在編寫程序中請使用這些宏。

  1. 數據類型

表-1.1中黑體字部分為替代數據類型的宏

Generic-Text Data Type Mappings

Generic-Text Data Type Name

SBCS (_UNICODE, _MBCS Not Defined)


_MBCS Defined


_UNICODE Defined

_TCHAR

Char

char

wchar_t

_TINT

Int

int

wint_t

_TSCHAR

signed char

signed char

wchar_t

_TUCHAR

unsigned char

unsigned char

wchar_t

_TXCHAR

Char

unsigned char

wchar_t

_T or _TEXT

No effect (removed by preprocessor)

No effect (removed by preprocessor)

L (converts following character or string to its Unicode counterpart)

表-1.1

  1. 函數

表-1.2中黑體字部分為替代函數的宏

Generic-Text Routine Mappings

Generic-Text
Routine Name

SBCS (_UNICODE &
MBCS Not Defined)


_MBCS Defined


_UNICODE Defined

_fgettc

fgetc

fgetc

fgetwc

_fgettchar

fgetchar

fgetchar

_fgetwchar

_fgetts

fgets

fgets

fgetws

_fputtc

fputc

fputc

fputwc

_fputtchar

fputchar

fputchar

_fputwchar

_fputts

fputs

fputs

fputws

_ftprintf

fprintf

fprintf

fwprintf

_ftscanf

fscanf

fscanf

fwscanf

_gettc

getc

getc

getwc

_gettchar

getchar

getchar

getwchar

_getts

gets

gets

getws

_istalnum

isalnum

_ismbcalnum

iswalnum

_istalpha

isalpha

_ismbcalpha

iswalpha

_istascii

__isascii

__isascii

iswascii

_istcntrl

iscntrl

iscntrl

iswcntrl

_istdigit

isdigit

_ismbcdigit

iswdigit

_istgraph

isgraph

_ismbcgraph

iswgraph

_istlead

Always returns false

_ismbblead

Always returns false

_istleadbyte

Always returns false

isleadbyte

Always returns false

_istlegal

Always returns true

_ismbclegal

Always returns true

_istlower

islower

_ismbclower

iswlower

_istprint

isprint

_ismbcprint

iswprint

_istpunct

ispunct

_ismbcpunct

iswpunct

_istspace

isspace

_ismbcspace

iswspace

_istupper

isupper

_ismbcupper

iswupper

_istxdigit

isxdigit

isxdigit

iswxdigit

_itot

_itoa

_itoa

_itow

_ltot

_ltoa

_ltoa

_ltow

_puttc

putc

putc

putwc

_puttchar

putchar

putchar

putwchar

_putts

puts

puts

putws

_tmain

main

main

wmain

_sntprintf

_snprintf

_snprintf

_snwprintf

_stprintf

sprintf

sprintf

swprintf

_stscanf

sscanf

sscanf

swscanf

_taccess

_access

_access

_waccess

_tasctime

asctime

asctime

_wasctime

_tccpy

Maps to macro or inline function

_mbccpy

Maps to macro or inline function

_tchdir

_chdir

_chdir

_wchdir

_tclen

Maps to macro or inline function

_mbclen

Maps to macro or inline function

_tchmod

_chmod

_chmod

_wchmod

_tcreat

_creat

_creat

_wcreat

_tcscat

strcat

_mbscat

wcscat

_tcschr

strchr

_mbschr

wcschr

_tcsclen

strlen

_mbslen

wcslen

_tcscmp

strcmp

_mbscmp

wcscmp

_tcscoll

strcoll

_mbscoll

wcscoll

_tcscpy

strcpy

_mbscpy

wcscpy

_tcscspn

strcspn

_mbscspn

wcscspn

_tcsdec

_strdec

_mbsdec

_wcsdec

_tcsdup

_strdup

_mbsdup

_wcsdup

_tcsftime

strftime

strftime

wcsftime

_tcsicmp

_stricmp

_mbsicmp

_wcsicmp

_tcsicoll

_stricoll

_stricoll

_wcsicoll

_tcsinc

_strinc

_mbsinc

_wcsinc

_tcslen

strlen

strlen

wcslen

_tcslwr

_strlwr

_mbslwr

_wcslwr

_tcsnbcnt

_strncnt

_mbsnbcnt

_wcnscnt

_tcsncat

strncat

_mbsnbcat

wcsncat

_tcsnccat

strncat

_mbsncat

wcsncat

_tcsncmp

strncmp

_mbsnbcmp

wcsncmp

_tcsnccmp

strncmp

_mbsncmp

wcsncmp

_tcsnccnt

_strncnt

_mbsnccnt

_wcsncnt

_tcsnccpy

strncpy

_mbsncpy

wcsncpy

_tcsncicmp

_strnicmp

_mbsnicmp

_wcsnicmp

_tcsncpy

strncpy

_mbsnbcpy

wcsncpy

_tcsncset

_strnset

_mbsnset

_wcsnset

_tcsnextc

_strnextc

_mbsnextc

_wcsnextc

_tcsnicmp

_strnicmp

_mbsnicmp

_wcsnicmp

_tcsnicoll

_strnicoll

_strnicoll

_wcsnicoll

_tcsninc

_strninc

_mbsninc

_wcsninc

_tcsnccnt

_strncnt

_mbsnccnt

_wcsncnt

_tcsnset

_strnset

_mbsnbset

_wcsnset

_tcspbrk

strpbrk

_mbspbrk

wcspbrk

_tcsspnp

_strspnp

_mbsspnp

_wcsspnp

_tcsrchr

strrchr

_mbsrchr

wcsrchr

_tcsrev

_strrev

_mbsrev

_wcsrev

_tcsset

_strset

_mbsset

_wcsset

_tcsspn

strspn

_mbsspn

wcsspn

_tcsstr

strstr

_mbsstr

wcsstr

_tcstod

strtod

strtod

wcstod

_tcstok

strtok

_mbstok

wcstok

_tcstol

strtol

strtol

wcstol

_tcstoul

strtoul

strtoul

wcstoul

_tcsupr

_strupr

_mbsupr

_wcsupr

_tcsxfrm

strxfrm

strxfrm

wcsxfrm

_tctime

ctime

ctime

_wctime

_texecl

_execl

_execl

_wexecl

_texecle

_execle

_execle

_wexecle

_texeclp

_execlp

_execlp

_wexeclp

_texeclpe

_execlpe

_execlpe

_wexeclpe

_texecv

_execv

_execv

_wexecv

_texecve

_execve

_execve

_wexecve

_texecvp

_execvp

_execvp

_wexecvp

_texecvpe

_execvpe

_execvpe

_wexecvpe

_tfdopen

_fdopen

_fdopen

_wfdopen

_tfindfirst

_findfirst

_findfirst

_wfindfirst

_tfindnext

_findnext

_findnext

_wfindnext

_tfopen

fopen

fopen

_wfopen

_tfreopen

freopen

freopen

_wfreopen

_tfsopen

_fsopen

_fsopen

_wfsopen

_tfullpath

_fullpath

_fullpath

_wfullpath

_tgetcwd

_getcwd

_getcwd

_wgetcwd

_tgetenv

getenv

getenv

_wgetenv

_tmain

main

main

wmain

_tmakepath

_makepath

_makepath

_wmakepath

_tmkdir

_mkdir

_mkdir

_wmkdir

_tmktemp

_mktemp

_mktemp

_wmktemp

_tperror

perror

perror

_wperror

_topen

_open

_open

_wopen

_totlower

tolower

_mbctolower

towlower

_totupper

toupper

_mbctoupper

towupper

_tpopen

_popen

_popen

_wpopen

_tprintf

printf

printf

wprintf

_tremove

remove

remove

_wremove

_trename

rename

rename

_wrename

_trmdir

_rmdir

_rmdir

_wrmdir

_tsearchenv

_searchenv

_searchenv

_wsearchenv

_tscanf

scanf

scanf

wscanf

_tsetlocale

setlocale

setlocale

_wsetlocale

_tsopen

_sopen

_sopen

_wsopen

_tspawnl

_spawnl

_spawnl

_wspawnl

_tspawnle

_spawnle

_spawnle

_wspawnle

_tspawnlp

_spawnlp

_spawnlp

_wspawnlp

_tspawnlpe

_spawnlpe

_spawnlpe

_wspawnlpe

_tspawnv

_spawnv

_spawnv

_wspawnv

_tspawnve

_spawnve

_spawnve

_wspawnve

_tspawnvp

_spawnvp

_spawnvp

_tspawnvp

_tspawnvpe

_spawnvpe

_spawnvpe

_tspawnvpe

_tsplitpath

_splitpath

_splitpath

_wsplitpath

_tstat

_stat

_stat

_wstat

_tstrdate

_strdate

_strdate

_wstrdate

_tstrtime

_strtime

_strtime

_wstrtime

_tsystem

system

system

_wsystem

_ttempnam

_tempnam

_tempnam

_wtempnam

_ttmpnam

tmpnam

tmpnam

_wtmpnam

_ttoi

atoi

atoi

_wtoi

_ttol

atol

atol

_wtol

_tutime

_utime

_utime

_wutime

_tWinMain

WinMain

WinMain

wWinMain

_ultot

_ultoa

_ultoa

_ultow

_ungettc

ungetc

ungetc

ungetwc

_vftprintf

vfprintf

vfprintf

vfwprintf

_vsntprintf

_vsnprintf

_vsnprintf

_vsnwprintf

_vstprintf

vsprintf

vsprintf

vswprintf

_vtprintf

vprintf

vprintf

vwprintf

表1.2

表1.4中黑體字部分為替代宏的宏

Generic-Text Marco Mappings

Generic-Text –
Object Name

SBCS (_UNICODE,
_MBCS Not Defined)

_MBCS Defined

_UNICODE
Defined

LPCTSTR

LPCSTR(CONST CHAR*)?

LPCSTR(CONST CHAR*)

CONST WCHAR*(const unsigned short*)

LPTSTR

LPSTR(CHAR*)?

LPSTR(CHAR*)?

WCHAR*(unsigned short*)?

表1.3

  1. 常量和全局變量

表1.4中黑體字部分為替代常量和全局變量的宏

Generic-Text Constant and Global Variable Mappings

Generic-Text –
Object Name

SBCS (_UNICODE,
_MBCS Not Defined)

_MBCS Defined

_UNICODE
Defined

_TEOF

EOF

EOF

WEOF

_tenviron

_environ

_environ

_wenviron

_tfinddata_t

_finddata_t

_finddata_t

_wfinddata_t

表-1.4

  1. 不能轉換的函數

atof替換方案

創建函數atof

#ifdef _UNICODE

double my_atof( LPCTSTR string )

{

assert( string!= NULL );

//double f3;

//_stscanf(string, _T("%lf"), &f3) ;//double

float f;

_stscanf(string, _T("%f"), &f) ;//float

return f;

}

#else

double my_atof( LPCTSTR string )

{

assert( string != NULL );

return atof(string);

}

#endif

fcvt替換方案

創建函數my_fcvt,如下:(注:FLT_EPSILON在float.h中)

#ifdef _UNICODE

LPCTSTR my_fcvt( double value, int count, int *dec, int *sign )

{

????static TCHAR szValue[32];

????

????if ( value < FLT_EPSILON && value > -FLT_EPSILON )

????{

????????*dec = 0;

????????*sign = 0;

????????_stprintf(szValue, _T("%0*d"), count, 0);

????????return (LPTSTR)&szValue;

????}

?

????if( value > FLT_EPSILON )

????????*sign = 0;

????else

????{

????????*sign = 1;

????????value = -value;

????}

????*dec = 0;

????

????int nSize = _stprintf(szValue, _T("%.*f"), count, value);

????if( nSize > 0 )

????{

????????//remove "."

????????LPTSTR pstrSource = szValue;

????????LPTSTR pstrDest = szValue;

????????LPTSTR pstrEnd = szValue + nSize;

????????LPTSTR pstrPoint = szValue;

????????

????????while (pstrSource < pstrEnd)

????????{

????????????if (*pstrSource != '.')

????????????{

????????????????*pstrDest = *pstrSource;

????????????????pstrDest = _tcsinc(pstrDest);

????????????}

????????????else

????????????{

????????????????pstrPoint = pstrDest;

????????????}

????????????pstrSource = _tcsinc(pstrSource);

????????}

????????*pstrDest = '\0';

????????

????????//trim "0"

????????pstrDest = szValue;

????????while (*pstrDest != '\0')

????????{

????????????if (_tcschr(_T("0"), *pstrDest) == NULL)

????????????????break;

????????????pstrDest = _tcsinc(pstrDest);

????????}

????????if (pstrDest != szValue)

????????{

????????????int nDataLength = _tcslen(szValue) - (pstrDest - szValue);

????????????memmove(szValue, pstrDest, (nDataLength+1)*sizeof(TCHAR));

????????}

????????*dec = pstrPoint - pstrDest;

????}

????return (LPCTSTR)&szValue;

}

#else

inline LPCTSTR my_fcvt( double value, int count, int *dec, int *sign )

{

????return _fcvt( value, count, dec, sign );

}

#endif

  1. UNICODE文本文件的讀寫

對于UNICODE的文本文件,實際上就是雙字節的二進制文件,該文件包含兩個字節的文件頭,內容是byte-order mark (BOM)值是0xfffe或0xfeff,表示字節的順序,在這里使用的是0xfffe。

下面是一個寫、讀文件的例程:

#ifdef UNICODE

????FILE* fp;

????fp = _tfopen(_T("c:\\1.txt"), _T("w+b"));

????if( fp != NULL )

????{

????????LPCTSTR buf = _T("abc\r\n");

????????const BYTE head[] = {0xff, 0xfe};//BOM(byte-order mark)

????????fwrite(head, sizeof(BYTE), sizeof(head)/sizeof(BYTE), fp);

????????fwrite(buf, sizeof(TCHAR), _tcslen(buf), fp);

????????fclose(fp);

????}

#endif

?

????fp = _tfopen(_T("c:\\1.txt"), _T("r+t"));

?

#ifdef UNICODE

????if( fp != NULL )

????{

????????TCHAR text[512];

????????memset(text, 0, sizeof(text));

????????fread(text, sizeof(TCHAR), sizeof(text)-1, fp);

????????int ret;

????????IsTextUnicode(text, _tcslen(text), &ret);

????????LPTSTR pBuf = text;

????????if( ret & IS_TEXT_UNICODE_SIGNATURE )

????????{

????????????pBuf ++;//文本的內容

????????}

????????fclose(fp);

????}

#endif

  1. 工程轉換方案

如果VC6.0工程選擇的是中文,在菜單Projects->Setting的C/C++屬性頁中,把Preprocessor definitinons: _MBCS改為_UNICODE,如果是英文的工程則直接加入_UNICODE。

如果工程是EXE文件,則須在Link屬性頁中,選擇Category為Output,把Entry-point symbol:設置為wWinMainCRTStartup,如果工程不是EXE文件,則不需要改變。

最后點擊OK即可。

  1. 附:ANSI、DBCS 和 Unicode 的定義

Unicode 是一種用兩個字節表示一個字符的字符集。另外一些程序,如 Windows 95 API,使用 ANSI (American National Standards Institute) 或 DBCS 存儲和操作字符串。

  1. ANSI

ANSI 是個人計算機使用得最普遍的字符集。由于 ANSI 標準使用單一字節表示每個字符,因此最多只能有 256 個字符和標點符號代碼。雖然對英語來說已經足夠了,但不能完全支持其它語言。

  1. DBCS

發行在亞洲大部分地區的 Microsoft Windows 系統使用 DBCS。它支持很多不同的東亞語言字母,如漢語、日語和朝鮮語。DBCS 使用數字 0–128 表示 ASCII 字符集。其它大于 128 的數字作為前導字節字符,它并不是真正的字符,只是簡單的表明下一個字符屬于非拉丁字符集。在 DBCS 中,ASCII 字符的長度是一個字節,而日語、朝鮮語和其它東亞字符的長度是 2 個字節。

  1. Unicode

Unicode 是用兩個字節表示每個字符的字符編碼方案。國際標準組織 (ISO) 幾乎為每種語言的每個字符和符號在 0 到 65,535 (216 – 1) 范圍內定義了一個數字(再加上為將來發展保留的一些空余空間)。在所有 32 位版本的 Windows 中,部件對象模型 (COM) 都使用 Unicode,它是 OLE 和 ActiveX 技術的基礎。Windows NT 全部支持 Unicode。雖然 Unicode 和 DBCS 都是雙字節字符,但它們的編碼方案完全不同。

轉載于:https://www.cnblogs.com/MakeView660/p/9699036.html

總結

以上是生活随笔為你收集整理的VC++关于UNICODE版本的开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。