const char* to LPCTSTR conversion
-
Hello, How can I convert const char* to LPCTSTR? I tried to use WideCharToMultiByte so that I could have a LPCWSTR then convert to LPCTSTR but the value of LPCWSTR(pdbfilename) on watch during breakpoint at line 9 is "???". (see code below) 1 HANDLE 2 fCreate(const char *fname, UInt32 access, UInt32 shared, UInt32 create, UInt32 attrib, Err *r_) 3 { 4 Err r = errNone; 5 HANDLE handle = NULL; 6 LPSTR holder=(LPSTR)fname; 7 LPCWSTR pdbfilename; 8 WideCharToMultiByte(CP_OEMCP, WC_DEFAULTCHAR,pdbfilename, -1,holder,strlen(fname),NULL, NULL); 9 handle = CreateFile(pdbfilename, access, shared, NULL, create, attrib, NULL); 10 if(handle == INVALID_HANDLE_VALUE) r = ERR_FILE_CREATEOPENFAILED; 11 if(r_ != NULL) 12 *r_ = r; 13 return handle; 14 } Is there something wrong with my WideCharToMultiByte API call? Is there other way to convert const char* to LPCTSTR? Thanks and more power.
-
Hello, How can I convert const char* to LPCTSTR? I tried to use WideCharToMultiByte so that I could have a LPCWSTR then convert to LPCTSTR but the value of LPCWSTR(pdbfilename) on watch during breakpoint at line 9 is "???". (see code below) 1 HANDLE 2 fCreate(const char *fname, UInt32 access, UInt32 shared, UInt32 create, UInt32 attrib, Err *r_) 3 { 4 Err r = errNone; 5 HANDLE handle = NULL; 6 LPSTR holder=(LPSTR)fname; 7 LPCWSTR pdbfilename; 8 WideCharToMultiByte(CP_OEMCP, WC_DEFAULTCHAR,pdbfilename, -1,holder,strlen(fname),NULL, NULL); 9 handle = CreateFile(pdbfilename, access, shared, NULL, create, attrib, NULL); 10 if(handle == INVALID_HANDLE_VALUE) r = ERR_FILE_CREATEOPENFAILED; 11 if(r_ != NULL) 12 *r_ = r; 13 return handle; 14 } Is there something wrong with my WideCharToMultiByte API call? Is there other way to convert const char* to LPCTSTR? Thanks and more power.
I thought LPCTSTR WAS a char * ? Anyhow, the easiest way to convert is to use the _bstr_t class, which is a string class that returns wide and narrow strings automagically. Christian Graus - Microsoft MVP - C++
-
I thought LPCTSTR WAS a char * ? Anyhow, the easiest way to convert is to use the _bstr_t class, which is a string class that returns wide and narrow strings automagically. Christian Graus - Microsoft MVP - C++
Hi Christian, Actually, the function belongs to a library and so the library is restricted to plain C so that it will be portable because I'am developing under Pocket PC environment. Let me rephrase the question, on EVC4 LPCTSTR is unsigned short*, my first parameter (fname) is const char*, so how can i convert const char* to unsigned short*? Thanks a lot Christian, Fjlv2005
-
Hi Christian, Actually, the function belongs to a library and so the library is restricted to plain C so that it will be portable because I'am developing under Pocket PC environment. Let me rephrase the question, on EVC4 LPCTSTR is unsigned short*, my first parameter (fname) is const char*, so how can i convert const char* to unsigned short*? Thanks a lot Christian, Fjlv2005
OK, if you want to do it in C, _bstr_t won't help, it's a class. However, it just calls the API function that you're trying to call now, anyhow. You could check it's source to see if it differs from your syntax. Christian Graus - Microsoft MVP - C++
-
OK, if you want to do it in C, _bstr_t won't help, it's a class. However, it just calls the API function that you're trying to call now, anyhow. You could check it's source to see if it differs from your syntax. Christian Graus - Microsoft MVP - C++
-
Hello, How can I convert const char* to LPCTSTR? I tried to use WideCharToMultiByte so that I could have a LPCWSTR then convert to LPCTSTR but the value of LPCWSTR(pdbfilename) on watch during breakpoint at line 9 is "???". (see code below) 1 HANDLE 2 fCreate(const char *fname, UInt32 access, UInt32 shared, UInt32 create, UInt32 attrib, Err *r_) 3 { 4 Err r = errNone; 5 HANDLE handle = NULL; 6 LPSTR holder=(LPSTR)fname; 7 LPCWSTR pdbfilename; 8 WideCharToMultiByte(CP_OEMCP, WC_DEFAULTCHAR,pdbfilename, -1,holder,strlen(fname),NULL, NULL); 9 handle = CreateFile(pdbfilename, access, shared, NULL, create, attrib, NULL); 10 if(handle == INVALID_HANDLE_VALUE) r = ERR_FILE_CREATEOPENFAILED; 11 if(r_ != NULL) 12 *r_ = r; 13 return handle; 14 } Is there something wrong with my WideCharToMultiByte API call? Is there other way to convert const char* to LPCTSTR? Thanks and more power.