Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting from const char * to LPTSTR without USES_CONVERSTION

I am trying to convert const char * to LPTSTR. But i do not want to use USES_CONVERSION to perform that.

The following is the code i used to convert using USES_CONVERSION. Is there a way to convert using sprintf or tcscpy, etc..?

USES_CONVERSION;
jstring JavaStringVal = (some value passed from other function);
const char *constCharStr = env->GetStringUTFChars(JavaStringVal, 0);    
LPTSTR lpwstrVal = CA2T(constCharStr); //I do not want to use the function CA2T..
like image 417
Santron Manibharathi Avatar asked Feb 04 '13 07:02

Santron Manibharathi


1 Answers

LPTSTR has two modes:

An LPWSTR if UNICODE is defined, an LPSTR otherwise.

#ifdef UNICODE
    typedef LPWSTR LPTSTR;
#else
    typedef LPSTR LPTSTR;
#endif

or by the other way:

LPTSTR is wchar_t* or char* depending on _UNICODE

if your LPTSTR is non-unicode:

according to MSDN Full MS-DTYP IDL documentation, LPSTR is a typedef of char *:

typedef char* PSTR, *LPSTR;

so you can try this:

const char *ch = "some chars ...";
LPSTR lpstr = const_cast<LPSTR>(ch);
like image 93
Reza Ebrahimi Avatar answered Oct 30 '22 14:10

Reza Ebrahimi