Link to home
Start Free TrialLog in
Avatar of pampa34
pampa34

asked on

Convert from LPSTR to LPCWSTR and LPSTR to char*

Hi,
Could somebody provide me an URL or a sample code to convert a LPSTR string to LPCWSTR and from LPSTR string to char*.

Thanks in advance,
Pampa
Avatar of Axter
Axter
Flag of United States of America image

windows project can use the MultiByteToWideChar API function to convert an ANSI string to a UNICODE string.
No conversion is required for converting a LPSTR to char*.

Example:

      LPSTR str1 = "Hello World";
      char* str2 = str1;
      char  str3[33];
      strcpy(str3, str1);
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hyperon
Hyperon

you should be able to simply typecast them eg.

LPCWSTR mylpcwstr = (LPCWSTR) mylpstr;
char *mypchar = (char *) mylpstr;

this has always worked for me :)