Skip to main content
gamedev.net
🔒 Locked

problems with D3DFont

Started by SiS-Shadowman Apr 1, 2006 at 2:15 PM 1 replies 800+ views
Original Post
SiS-Shadowman
SiS-Shadowman
hi i'm using the 'D3DFont.cpp/D3DFont.h' from Microsoft to display any text in my game. i have now written a new game kernel, that works with visual studio 2005, because the old one didn't :) i now wanted to include the file and draw some text to the screen, but there's a problem, the Function 'DrawTextScaled' now wants the text in a const TCHAR pointer, but i always had just a char pointer for my text to be stored, how can i change this now? i'm using sprintf(...) to write the data to be displayed in the buffer, but this function doesn't accept TCHAR, is there something similar to it, but also accepting TCHAR? would appretiate it, if there was one ;)
Evil Steve
Evil Steve
A TCHAR is just a typedef. In a unicode build, a TCHAR evaluates to a wchar_t, and in a non-unicode build it evaluates to a char.
So, if you're using a non-unicode build, you shouldn't need to convert (Althoguh it's not ideal).

If you do want to convert, look at MultiByteToWideChar and WideCharToMultiByte. You'll need to use a #ifdef UNICODE block to determine if you need to do the conversion.

If you're passing in const strings, then declare them with the TEXT() macro, E.g. TEXT("This is some text"). That'll cause them to be declared as a const char* in non-unicode builds, or const wchar_t* in unicode builds (Basically a TCHAR* or LPCTSTR)

As for sprintf, you need to use swprintf for unicode strings.
SiS-Shadowman
SiS-Shadowman
ah, thanks, this worked :)

but i have another question.
i've declared 'LPCWSTR Speicherpfad;' to save a path to a file, because the 'D3DXCreateTextureFromFileEx()' Function needs a LPCWSTR... *rolleyes*
how do i convert a char* to this datatype? the compiler won't accept swprintf, although the msdn tells me:

typedef CONST WCHAR *LPCWSTR;
typedef wchar_t WCHAR;

the compiler says (it's in german, thats why i don't print the message here...) that he coulnd't convert the arguments (LPCWSTR *__w64 , const wchar_t [3], const wchar_t [12]) to either of these two declarations:
int swprintf(wchar_t *,size_t,const wchar_t *,...)
int swprintf(wchar_t *,const wchar_t *,...)

what is wrong here?


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.