Solved

Convert from LPSTR to LPCWSTR and LPSTR to char*

Posted on 2004-04-12
8
5,833 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:pampa34
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
8 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 10804438
windows project can use the MultiByteToWideChar API function to convert an ANSI string to a UNICODE string.
0
 
LVL 30

Expert Comment

by:Axter
ID: 10804448
No conversion is required for converting a LPSTR to char*.

Example:

      LPSTR str1 = "Hello World";
      char* str2 = str1;
      char  str3[33];
      strcpy(str3, str1);
0
 
LVL 30

Accepted Solution

by:
Axter earned 75 total points
ID: 10804467
Example:
void Function(void)
{
   char dataBuff[] = "abcdefghijklmnopq";

   wchar_t pwsz[sizeof(dataBuff)*2];
   MultiByteToWideChar(CP_ACP, 0, dataBuff, strlen(dataBuff), pwsz, sizeof(pwsz));
   LPCWSTR Data = pwsz;
}

0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 75 total points
ID: 10805403
0
 

Expert Comment

by:Hyperon
ID: 10808972
you should be able to simply typecast them eg.

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

this has always worked for me :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question