Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type of string is best to use for Win32 and DirectX?

I am in the process of developing a small game in DirectX 10 and C++ and I'm finding it hell with the various different types of strings that are required for the various different directx / win32 function calls.

Can anyone recommend which of the various strings are available are the best to use, ideally it would be one type of string that gives a good cast to the other types (LPCWSTR and LPCSTR mostly). Thus far I have been using std::string and std::wstring and doing the .c_str() function to get it in to the correct format.

I would like to get just 1 type of string that I use to pass in to all functions and then doing the cast inside the function.

like image 229
Ian Cant Avatar asked Jan 24 '26 06:01

Ian Cant


2 Answers

Use std::wstring with c_str() exactly as you have been doing. I see no reason to use std::string on Windows, your code may as well always use the native UTF-16 encoding.

like image 79
David Heffernan Avatar answered Jan 25 '26 20:01

David Heffernan


I would stick to std::wstring as well. If you really need to pass std::string somewhere, you can still convert it on the fly:

std::string s = "Hello, World";
std::wstring ws(s.begin(), s.end());

It works the other way around as well.

like image 29
nijansen Avatar answered Jan 25 '26 19:01

nijansen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!