Unicode字符集、多字節字符集下:CString->const char*、CString->LPCSTR

Unicode字符集、多字節字符集下:CString->const char*、CString->LPCSTR

1、CString->const char*
(1)多字節字符集下:CString->LPCTSTR可以自動轉化!
(2)Unicode下:使用函數 “wsprintfA”

// BmpName->cstr_BmpName;
// CString BmpName;//變量BmpName
// const char* cstr_BmpName;////變量cstr_BmpName
// FILE * __cdecl fopen(_In_z_ const char * _Filename, _In_z_ const char * _Mode);
eg:	
	CString BmpName;//變量BmpName
	const char* cstr_BmpName;
	char temp[100];
	::wsprintfA(temp, "%ls", (LPCTSTR)BmpName);
	cstr_BmpName = temp;
	FILE *fpo = fopen(cstr_BmpName, "rb");

2、CString->LPCSTR
(1)多字節字符集下:CString->LPCTSTR可以自動轉化!

// void SaveBmp(LPCSTR lpFileName);
// CString str;
eg:
	SaveBmp(str);

(2)Unicode下:使用 “USES_CONVERSION” 和 “T2A”

// str -> lpstr
// CString str;
// LPCSTR lpstr;
eg:
	str = str + L".bmp";	
	USES_CONVERSION;
	LPCSTR lpstr = (LPCSTR)T2A(str);
	SaveBmp(lpstr); 

3、CString = CString + CString

// CString str;
多字節字符集下:str = str + ".bmp";
Unicode下:str = str + L".bmp";
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章