Sign in to follow this  
Slyfox

Unicode LPCWSTR's and passing std::wstring

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this