Cstring to char *
阿新 • • 發佈:2019-01-02
///cstring TO char *
CString 轉char *
CString cstr;
char *p = (LPSTR)(LPCTSTR)cstr;
好久沒有寫vc了,還是收集一下吧
void wcharTochar(const wchar_t *wchar, char *chr, int length)
{
WideCharToMultiByte( CP_ACP, 0, wchar, -1,
chr, length, NULL, NULL );
}
char *GetBuf(CString str)
{
CString origCString=_T("");
origCString = str;
wchar_t* wCharString = origCString.GetBuffer(origCString.GetLength()+1);
size_t origsize = wcslen(wCharString) + 1;
size_t convertedChars = 0;
char *CharString;
CharString=(char*)malloc(origsize);
wcharTochar(wCharString,CharString,origsize);
return CharString;
}