Having problems navigating?

c++ snippet - unicode strings

Ok, so admittedly I got quite annoyed when using function such as D3DXLoadMeshFromX(...) and D3DXCreateTextureFromFile(...). The string types that they take seem to swap almost randomly. So heres a small guide on how to use the functions and to change between the different string types.
So the main reason for having all these seemingly random string types is that a char can hold values from 0-256 (a byte) and were used for ISO 8859-1 character encodings. The problem is that in some languages we have a few million characters, if you combine that with all the characters in the world, that you might want to consider, it becomes a very large number.
To solve this problem we have to use unicode. This can hold up to 32 bits (4294967296 characters ^^).

Now that you know the reason we need the different string types, heres the main points on how to use them:

A unicode character (char equivalent) is a TCHAR. A unicode equivalent of a string (char *) is a LPTSTR. LP being a long-pointer... dont quite know why they keep that in there a sit is a remnant of older days.
So to convert a normal char character so it is able to be used in a function taking a unicode:

Youll need to include the ATL conversion headers to use these functions. I put them in my pre-compiled header stdafx.h (dxstdafx.h if your using directx). If you get errors saying it cannot find the header then you'll need to include the platform sdk include directory in your project. This was "C:/Program Files/Microsoft Platform SDK/include/atl" on my PC; yours might be different.

You may be wondering "thats going to take up alot of processor power" and if you are... good on you! The most uniform way of diong things is to use the type that will resolve to whatever you have chosen and then only convert when there is an old function that only takes certain types.