Jump to content
  • Advertisement
Sign in to follow this  
SiS-Shadowman

problems with D3DFont

This topic is 4494 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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 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?


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!