char* 轉換成 LPCTSTRide
const char* dibFileName; int num = MultiByteToWideChar(0, 0, dibFileName, -1, NULL, 0); wchar_t *wide = new wchar_t[num]; MultiByteToWideChar(0, 0, dibFileName, -1, wide, num);
char m_fileName[256]; // 這樣在多字節或UNICODE模式下均可以。 _bstr_t bstrTmp(m_fileName); LPCTSTR strTmp = (LPTSTR)bstrTmp;
解析:spa
num 得到長字節所需的空間
MultiByteToWideChar()表示將s中的字符傳遞到ps指向的內存中。-1表示傳輸至s中的'\0'處,num表示傳遞的字節個數。code
char* 轉換成 CStringblog
// char * -->CString // outputFilePath = "G:\\testDLL" const char* outputFilePath; CString str1(outputFilePath);
CString轉換成char* 內存
char * CDib::CStringToCharArray(CString str) { char *ptr; #ifdef _UNICODE LONG len; len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL); ptr = new char[len + 1]; memset(ptr, 0, len + 1); WideCharToMultiByte(CP_ACP, 0, str, -1, ptr, len + 1, NULL, NULL); #else ptr = new char[str.GetAllocLength() + 1]; sprintf(ptr, _T("%s"), str); #endif return ptr; }