CString strTest;
...
LPBYTE lpData = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, LIMIT_SIZE);
...
if(lpData)
{
CopyMemory(lpData, (LPCTSTR)strTest, strTest.GetLength());
}
...
if(lpData)
{
HeapFree(GetProcessHeap(), 0, lpData);
}
...
LPBYTE lpData = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, LIMIT_SIZE);
...
if(lpData)
{
CopyMemory(lpData, (LPCTSTR)strTest, strTest.GetLength());
}
...
if(lpData)
{
HeapFree(GetProcessHeap(), 0, lpData);
}
CString str;//str = "somevalue";
lpBuffer = ::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, 1025);::CopyMemory(lpBuffer, (LPCTSTR)str, str.GetLength());::HeapFree(::GetProcessHeap(), 0, lpBuffer);@C msdn CString Reference