• Advertisement
Sign in to follow this  

displaying text

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

I am trying to display some text using dx 9 and c++.here is the code I am using.
void DisplaySomeText()
[code]
{
D3DCOLOR fontColor = D3DCOLOR_XRGB(255,0,0);
RECT rct;
rct.left=200;
rct.right=600;
rct.top=20;
rct.bottom =40;
g_Font-> DrawText(NULL,"Hello World",-1,&rct,0,fontColor);
}
[/code]

Share this post


Link to post
Share on other sites
Advertisement
yes in the following code, I am trying to pass in a string to be displayed on the screen.
[code]
void DisplaySomeText(string text)
{
D3DCOLOR fontColor = D3DCOLOR_XRGB(255,0,0);
RECT rct;
rct.left=200;
rct.right=600;
rct.top=20;
rct.bottom =40;
g_Font-> DrawText(NULL,text,-1,&rct,0,fontColor);
}
[/code]
the text field in the drawtext line is giving me an error.

Share this post


Link to post
Share on other sites
It's funny, but error messages often tell you what the problem is. While I can probably guess what your problem is from the code, you should probably examine the error message carefully and try to understand what it means. Try to break it down into pieces and see what parts you can understand and what parts you don't understand. And then ask a [i]specific question[/i] about the parts you don't understand.

Share this post


Link to post
Share on other sites
I am getting a runtime error with this line of code.
g_font-> DrawText(NULL,"HelloWorld",-1,&rct,0,fontColor);
everything else appears ok
let me know if you need more code.

Share this post


Link to post
Share on other sites
[quote name='phil67rpg' timestamp='1351373498' post='4994531']
I am getting a runtime error with this line of code.
g_font-> DrawText(NULL,"HelloWorld",-1,&rct,0,fontColor);
everything else appears ok
let me know if you need more code.
[/quote]

POST THE FRIGGING ERROR PHIL.

Share this post


Link to post
Share on other sites
The fix is .c_str() on the std::string you are passing in. DrawText wants a pointer to the first character of the string array. When documentation states that it wants a pointer to a text string and is defined as LPCSTR it means that it wants a pointer to the first element of the character array of a string. Std::string is a wrapper over a dynamically resizing character array, to get access to the raw memory you need to use the function "c_str()" Edited by NightCreature83

Share this post


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

  • Advertisement