Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use std::string or Windows data types with DirectX?

I have been working now on a project based on DirectX and I am struggling with something. Though the DirectX SDK relies heavily on Windows data types like LPSTR, LPCSTR, ... I have been using for my own classes std::string which was quite easy to work with, but it looks strange to mix both ways of handling strings. Although this is a vague question, what do you suggest - should I work with the strings or with the Windows pointers for different string types to keep some consistency?

like image 858
Christian Ivicevic Avatar asked Feb 17 '23 16:02

Christian Ivicevic


1 Answers

LPSTR is just an alias for char* and LCPSTR is an alias for const char*, so your question actually sounds like "Should I use C++ strings or C strings?"

Well, C++ std::string has a member function called c_str() (or the equivalent data() function for STL compatibility) that returns a (non-modifiable) C string. So any time a function accepts an LPCTSTR, you can provide the output of c_str() as an argument.

I suggest you working with C++ std::string whenever you can, it is safer.

like image 57
Andy Prowl Avatar answered Feb 20 '23 21:02

Andy Prowl