Solved

Convert from LPSTR to LPCWSTR and LPSTR to char*

Posted on 2004-04-12
8
5,682 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now