473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

conversion from const char * to LPCWSTR

How do i convert const char * to LPCWSTR?
Aug 13 '08 #1
5 124081
weaknessforcats
9,208 Expert Mod 8TB
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
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
kubano
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
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
your solution for altering the character set to Multi-Byte worked marvelously! Much thanks !
May 3 '10 #6

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

Similar topics

30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
10
by: kevin.hall | last post by:
GCC 3.3 and MSVS 6.0 have no problem converting char* to const char* (not even a warning), but MS's WinCE compiler generated an error complained that this was not possible. MS's WinCE compiler did...
1
by: lovecreatesbeauty | last post by:
There is a warning/(error? I remember it is an error for line 10 on some compilers before. At least on g++, it is an error.) for line 10. I first read a similar example from `Expert C Programming...
1
by: asenthil | last post by:
Hai this is senthil... I had tried to write a string which fetched from a database. into a file... when i tried to compile the solution the following error occurs like this error C2664:...
3
by: Kevin Frey | last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the new C++/CLI syntax rather than /clr:oldSyntax. Much of our managed code is concerned with interfacing to native C++...
10
by: lovecreatesbea... | last post by:
C stops the conversion from (char **) to (const char **). c-faq.com sec 11.10 has explanation on this point. But, for example, even the conversion from (char *) to (const char *) brings the same...
6
by: mihai | last post by:
Hi, I have a question regarding the conversion (in c or c++) from char** to const char**. The fallowing code refuses :) to compile with g++ (and others): char **p; const char **q =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.