By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,953 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,953 IT Pros & Developers. It's quick & easy.

conversion from const char * to LPCWSTR

P: 21
How do i convert const char * to LPCWSTR?
Aug 13 '08 #1
Share this Question
Share on Google+
5 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
This can be done several ways:

Expand|Select|Wrap|Line Numbers
  1. const char* c = "Hello";
  2. LPCWSTR str = TEXT("Hello");
  3. LPCWSTR str1 = L"Hello";
  4. LPCWSTR str2 = _T("Hello");
  5. WCHAR    str3[6];
  6. MultiByteToWideChar( 0,0, c, 5, str3, 6);
  7. LPCWSTR cstr4 = str3;
  8.  
Read this:


http://msdn.microsoft.com/en-us/library/cc500362.aspx
Aug 13 '08 #2

P: 21
This can be done several ways:

Expand|Select|Wrap|Line Numbers
  1. const char* c = "Hello";
  2. LPCWSTR str = TEXT("Hello");
  3. LPCWSTR str1 = L"Hello";
  4. LPCWSTR str2 = _T("Hello");
  5. WCHAR    str3[6];
  6. MultiByteToWideChar( 0,0, c, 5, str3, 6);
  7. LPCWSTR cstr4 = str3;
  8.  
Read this:


http://msdn.microsoft.com/en-us/library/cc500362.aspx

Thanks for help it work properly
Aug 21 '08 #3

P: 1
Hi.

I'm developing a small aplication for pocket pc and I have the same exception :

"cannot convert parameter 1 from 'const char *' to 'LPCWSTR' "

But i can't solve in this way.

I should know how to solve it... but i'm beginer in the language...

I can't use the functions... because i have the string in a variable (var)


Somebody can help me??
Nov 25 '09 #4

P: 1
I'm assuming your using Visual Studio.
The easiest solution to this problem is to change your solution settings from Unicode to Multi-btye.
VS sets windows applications to default to unicode. While unicode "may" be better, it certainly is more difficult for beginning programming and requires explicit conversions.

Right click on your Project, select Properties. Configuration Properties/General
And Character Set to Multi-Byte.
Apr 21 '10 #5

P: 1
your solution for altering the character set to Multi-Byte worked marvelously! Much thanks !
May 3 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.