Sign in to follow this  

Problem with DrawText function

This topic is 4197 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

Hello everyone im following a book intro to dx9 and having problems compiling the following code
char FPSString[9];



		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

		if( Font )
			Font->DrawText(20, 20, 0xff000000, FPSString);	

		Device->EndScene();
		Device->Present(0, 0, 0, 0);


and keep getting the following compile error c:\documents and settings\terry\desktop\intro to directx 10 source code\part 3\chapter 9\cfont\cfont.cpp(90) : error C2664: 'CD3DFont::DrawTextW' : cannot convert parameter 4 from 'char [9]' to 'const TCHAR *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast any way to resolve this i didnt want to make a lot more changes to the code as it messes it up more, lol o.o maybe im just being a noob and cant see the solution, thanks in advance

Share this post


Link to post
Share on other sites
ok so i changed FPSString from char to const TCHAR * and off course now i'm getting complie error

c:\documents and settings\terry\desktop\intro to directx 10 source code\part 3\chapter 9\cfont\cfont.cpp(75) : error C2664: 'sprintf' : cannot convert parameter 1 from 'TCHAR *[9]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

that doesnt work, any suggestions from anyone?

Share this post


Link to post
Share on other sites
Turn it back into a character array, and in your call to "DrawText", just make a simple C-style cast, "(TCHAR*)FPSString". I think you only need a special conversion function if you're dealing with Unicode, which Windows labels as "WCHAR*".

Share this post


Link to post
Share on other sites

This topic is 4197 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.

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