Reputation: 362
I am using _aligned_malloc in my code. But it is throwing error error as shown in image.
CString sBuffer = _T("Hello");
TCHAR* pBuffer;
pBuffer = (TCHAR *)_aligned_malloc(1024, 16);
if (pBuffer == NULL) {
...............Error .. msg
}
pBuffer = sBuffer.GetBuffer(sBuffer.GetLength());
..................................................
.........................................................
sBuffer.ReleaseBuffer(sBuffer.GetLength());
if (pBuffer != NULL) {
_aligned_free(pBuffer);
}
Upvotes: 0
Views: 63
Reputation: 6556
The CString
class implements (LPCTSTR)
cast operator that you can use to get const TCHAR*
.
Please note that TCHAR
is defined as char
in MBCS mode, and as wchar
in UNICODE mode. For more details please refer to tchar.h where its defined.
If you'd like to modify the content of the buffer you'll need to use GetBuffer()
method. Don't forget to call ReleaseBuffer()
when you done. So, there is no need to allocate memory manually.
You can also easily construct CString
from TCHAR*
. There is a constructor to do that.
Upvotes: 2