Jump to content

  • Log In with Google      Sign In   
  • Create Account

"const wchar_t" is incompatible with parameter of type "LPCSTR"


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 04 March 2013 - 10:54 AM

Hey there,

 

still fairly new to C++, having this issue in my code, as you can see from the screenshot

 

http://img203.imageshack.us/img203/8624/errorae.png

 

I know it might be something to do with MCBS and UNICODE strings, and that thing were you put an L before a quoted piece. But I'm unsure how to fix it.

 

fileNamePath is defined like this:

 

std::wstring fileNamePath;

 

If anyone could see what Im doing wrong Id be grateful! Thanks



Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5433

Like
0Likes
Like

Posted 04 March 2013 - 11:03 AM

Oh the excitement of waiting for your massive png to load. Use code tags.

 

But yes, you need to compile your program with UNICODE defined (use unicode char set) in order to use wstring with DX. wstring::c_str returns a const wchar_t* which is LPCWSTR in windows speak, a LPCSTR is a const char* (so result of calling c_str on a std::string).


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 04 March 2013 - 11:22 AM

Still unsure on how to fix this problem..



#4 Brother Bob   Moderators   -  Reputation: 8575

Like
1Likes
Like

Posted 04 March 2013 - 11:34 AM

Select Properties in the Project menu. Then, under Configuration Properties and General, change the parameter Character Set to Use Unicode Character Set.



#5 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 04 March 2013 - 11:38 AM

Select Properties in the Project menu. Then, under Configuration Properties and General, change the parameter Character Set to Use Unicode Character Set.

Thats fixed my related error, but has caused over 40 new errors.. Is there another way?



#6 Juliean   GDNet+   -  Reputation: 2721

Like
0Likes
Like

Posted 04 March 2013 - 12:16 PM

You have two (sensical) solutions:

 

- Select "Unicode", then replace every std::string, LPCSTR, LPSTR etc.. in your project with the unicode-counterpart (std::wstring, LPCWSTR, LPWSTR). Also, you need to write an "L" before every string (e.g.:  L"C:/Pictures/Test.png"). This should fix your errors, if not, some of your other included libaries might be using multibyte, I'd get to that if his prooves to be the case.

 

- Keep your project at Multibyte setting, and replace every std::wstring, LPCWSTR, LPWSTR in your project with the multibyte-counterpart (I've already named those).


Edited by The King2, 04 March 2013 - 12:17 PM.


#7 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 04 March 2013 - 12:26 PM

You have two (sensical) solutions:

 

- Select "Unicode", then replace every std::string, LPCSTR, LPSTR etc.. in your project with the unicode-counterpart (std::wstring, LPCWSTR, LPWSTR). Also, you need to write an "L" before every string (e.g.:  L"C:/Pictures/Test.png"). This should fix your errors, if not, some of your other included libaries might be using multibyte, I'd get to that if his prooves to be the case.

 

- Keep your project at Multibyte setting, and replace every std::wstring, LPCWSTR, LPWSTR in your project with the multibyte-counterpart (I've already named those).

Yes this has fixed my related error, but now I have problems with certain operands such as this one:

 

error1qv.jpg

Other operands are now erroring as well, such as:

if(fileNamePath == texFileNameArray[i])
texFileNameArray.push_back(fileNamePath.c_str()); 

(the full stop before push_back)

std::string message = "Could not open: ";
			message += filename; 

 

So how do I get round this?

 

Thanks



#8 Brother Bob   Moderators   -  Reputation: 8575

Like
2Likes
Like

Posted 04 March 2013 - 12:38 PM

Sounds like your program simply isn't consistent with what character set it uses. Proper text handling of almost any kind is not trivial as soon as different encodings comes into play. It seems like your code consists of a mix of narrow and wide characters/strings, and mixing text encodings can be a real problem.

 

Decide on one single encoding for your entire program, and stick with it everywhere. If you need to handle text in different encodings, then make helper functions that converts text between the proper encoding and your program's encoding. But ultimately, your core program should not handle more than one encoding.



#9 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 04 March 2013 - 12:43 PM

Well this is all new and annoying, but thanks for the help either way... I think I'm going to set it to Unicode and change everything text based and slap an L before all quotes..

 

Thanks again



#10 Adam_42   Crossbones+   -  Reputation: 2616

Like
2Likes
Like

Posted 04 March 2013 - 02:32 PM

There's a third option. If you only need to use Unicode (or ascii) versions of a handful of functions then you can call them directly by appending W (or A) to the function name.

 

For example the function GetGlyphOutline() is actually two functions. GetGlyphOutlineA() and GetGlyphOutlineW() and a define is set up depending on the Unicode setting to point to the right one. MSDN tells you that at the bottom of the documentation for the function. Only functions which work with text come in two versions like that.

 

That can be handy if you have lots of existing code that uses char * for things like file names, but want to add Unicode support for the user interface strings. Calling the right function explicitly lets you mix and match and avoid a lot of needless changes.



#11 BinaryPhysics   Members   -  Reputation: 294

Like
0Likes
Like

Posted 05 March 2013 - 09:52 AM

Win32 is all in C. The typedefs LPCSTR and LPCWSTR are C-style strings. You can't really pass a std::string directly to functions that take this type. Pass it the result of std::string::c_str().

 

Also, Windows has the define TEXT that will automatically mark a string as with either L or not based on the defines of MBS or UNICODE.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS