Sign in to follow this  

problems with D3DFont

Recommended Posts

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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 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?

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