CString和PBYTE如何相互转换

来源:百度知道 编辑:UC知道 时间:2024/06/17 15:03:28
由于程序的需要,使得此两种类型要相互转换,我尝试了一些方法未成功,希望有高手能解答一下。
已解决,还是谢谢回答者。O(∩_∩)O~

PBYTE pByte = new BYTE[10];
ZeroMemory(pByte,10*sizeof(BYTE));
CString strTemp;
strTemp = _T("123abc");
wcscat_s((wchar_t *)pByte,10*sizeof(BYTE),strTemp); //把cstring类型的值copy到pByte

strTemp.Empty();
strTemp.Format(_T("%s"),pByte); //PBYTE转换cstring

如果还有问题HI我

CString -> PBYTE

PBYTE* pBuffer= ( PBYTE)( (LPTSTR)(LPCTSTR)(str) );

PBYTE->CString
CString str = CString( LPCTSTR( LPTSTR( pBuffer) ) );