Jump to content
  • Advertisement
Sign in to follow this  
Slyfox

Unicode LPCWSTR's and passing std::wstring

This topic is 3201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm developing my latest project using unicode and have run into some issues, I'm not familiar with using LPCWSTR's or WCHAR's. I'm trying to use some of the code contained within DXUT but they demand that they are passed LPCWSTR's or LPWSTR's. I've done a little reading into this and it was suggested that this could be solved by using std::wstring and passing wstring into arguments using c_str(). However I'm still recieving errors such as "cannot convert parameter 1 from 'const wchar_t *' to 'LPWSTR'" and I'm not really sure how to solve this, I'm I approaching it in entirely the wrong fashion? I'm trying to use std::wstring because I want to be able to concatenate two strings together. Any help would be greatly appreciated! Cheers.

Share this post


Link to post
Share on other sites
Advertisement
In that specific case that you describe, you have to cast away the const to make the compiler happy.

A LPWSTR is a wchar_t * type and a LPCWSTR is a const wchar_t * type.

In your code, you just need to use a C or C++ cast to cast away the const. Here's a C-cast: (LPWSTR)myUnicodeStr.c_str()

In casting away the const, you do have to make sure the function will not actually modify the string's contents, since that's why the const is there in the first place! [wink]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!