?
Solved

Convert from LPSTR to LPCWSTR and LPSTR to char*

Posted on 2004-04-12
8
Medium Priority
?
5,990 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 300 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 300 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

771 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