Convert CString to const unsigned short *
-
This is a really bad idea. A CString is an object representing a memory area in the PC. You can interpret to a pointer BUT it should be temporary. => (LPCSTR). (const unsigned short *)(LPCSTR) But there is no unsigned short :doh:!!!! RTFM
Greetings from Germany
-
Use the MultiByteToWideChar() function. Other option is to define the _UNICODE in the project setting preprocessor definitions, so that the CString will be keeping wide characters internally and hence no conversion is requirent
nave [OpenedFileFinder]
-
This is a really bad idea. A CString is an object representing a memory area in the PC. You can interpret to a pointer BUT it should be temporary. => (LPCSTR). (const unsigned short *)(LPCSTR) But there is no unsigned short :doh:!!!! RTFM
Greetings from Germany
-
VARIANT v; First case: v.bstrVal = SysAllocString(sz); //where sz is a OLECHAR FAR* Second case: v.bstrVal =sz.AllocSysString(); //where sz is a CString Second case solved my problem
The right decription is often half of the solution of the problem!!! :cool: For these String conversion are some API function and macros available. Its better to use them. I dont need them often so I dont remember gut I guess like OLE2CHAR( ):confused:
Greetings from Germany
-
VARIANT v; First case: v.bstrVal = SysAllocString(sz); //where sz is a OLECHAR FAR* Second case: v.bstrVal =sz.AllocSysString(); //where sz is a CString Second case solved my problem
yashveer wrote:
v.bstrVal =sz.AllocSysString();
dont forget to free it using the SysFreeString().
nave [OpenedFileFinder]
-
yashveer wrote:
v.bstrVal =sz.AllocSysString();
dont forget to free it using the SysFreeString().
nave [OpenedFileFinder]
ya i m actually using SysFreeString() I wouldnt have known about all this. I was searching for a way to convert text to csv.... i found something on msdn online;-) http://support.microsoft.com/kb/179706/ Instead of fixed string given in the code: FillSafeArray(L"John", 0, 0, &saRet); I wanted to use the following: FillSafeArray(str, 0, 0, &saRet); where str is CString and hence....all this
-
You can use MultiByteToWideChar may be somethng like this CString str; wchar_t* wch MultiByteToWideChar(CP_ACP,0,str,strlen(str),wch,strlen(str),NULL,NULL) Don't forget to allocate memory to this wchar variable then typecast this wchar to unsigned short* FillSafeArray((unsigned short*)wch ,....) I think this will help u out !!!
-
You can use MultiByteToWideChar may be somethng like this CString str; wchar_t* wch MultiByteToWideChar(CP_ACP,0,str,strlen(str),wch,strlen(str),NULL,NULL) Don't forget to allocate memory to this wchar variable then typecast this wchar to unsigned short* FillSafeArray((unsigned short*)wch ,....) I think this will help u out !!!