Post by JagadeeshCString str = "Hello Daniel";
LPWSTR lpszW = new WCHAR[255];
LPTSTR lpStr =str.GetBuffer( str.GetLength() );
int nLen = MultiByteToWideChar(CP_ACP,0,lpStr, -1, NULL, NULL);
MultiByteToWideChar(CP_ACP, 0, lpStr, -1, lpszW,nLen);
After having done with lpszW, use delete[] lpszW;
There is no need to use GetBuffer(). If you do use it, you should call
ReleaseBuffer(). If you are going to call MultiByteToWideString() twice, you
should use the length it returns to size the array. The code you've given
could be a security risk if str changes.
Either:
CString str = "Hello Daniel";
int maxLenW = str.GetLength() * 2;
WCHAR *strW = new WCHAR[ maxLenW ];
MultiByteToWideChar(CP_ACP,0,str, -1, strW, maxLenW );
Or:
CString str = "Hello Daniel";
int lenW = MultiByteToWideChar(CP_ACP,0,str, -1, 0, 0 );
WCHAR *strW = new WCHAR[ lenW ];
MultiByteToWideChar(CP_ACP,0,str, -1, strW, lenW );
-- Dave Harris