描述:
谢谢
解决方案1:
以下代码经过初步调试:
#define BUFFER_SIZE 100
HGLOBAL hMem = GlobalAlloc(GMEM_FIXED, BUFFER_SIZE);
if (hMem == NULL) return;
IStream* pStream = NULL;
CreateStreamOnHGlobal(hMem , FALSE, &pStream );
if (pStream == NULL)
{
GlobalFree(hMem );
return;
}
// CString ---> IStream
CString str = _T("Hello World!");
const char * pBuffer = str.GetBuffer(BUFFER_SIZE);
ULONG cbWritten;
pStream->Write(pBuffer,str.GetLength(),&cbWritten);
str.ReleaseBuffer();
pBuffer = NULL;
// Now hMem == "Hello World!"
// IStream -->CString
char pTest[BUFFER_SIZE] ={0};
ULONG cbRead;
ULARGE_INTEGER pSeek;
LARGE_INTEGER dlibMove ={ 0 } ;
pStream->Seek(dlibMove,STREAM_SEEK_SET ,&pSeek);
pStream->Read(pTest,str.GetLength(),&cbRead);
CString strTest = pTest;
// Now strTest = "Hello World!"
GlobalFree(hMem);