Jump to content
  • Advertisement
Sign in to follow this  
Xpyder

Trouble adding LPSTRs

This topic is 4884 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 am making a text box class, and it is going well except for when i want the new char to be added to the text. Obviously, in accordance with D3DXFont my messages must use LPSTR and not chars, but for this or some other reason my program crashes when i use strcat() to add them together - is this because LPSTR is a pointer to a char or some other reason?

Share this post


Link to post
Share on other sites
Advertisement
If i was doing it I'd use a std::string and when I wanted an LPSTR I would do this:

std::string ss = "blah";
LPSTR ws = (LPSTR)ss.c_str();

Share this post


Link to post
Share on other sites
All LPSTR is is an alias for char*. So as such you can ignore this syntax completely and use standard character arrays.

char text[MAX_TEXT_SIZE]
...
strcat( text, input_char );
...

Can't remember the syntax off the top of my head, but now you would just pass text as the LPSTR. This is because character arrays are actually just character pointers with added restrictions (because they are not dynamically allocated with new).

WriteText( text );

Good luck!

Share this post


Link to post
Share on other sites
I haven't used DX, but you should be able to use the c_str() method of an std::string, which is my favorite string class. It simply returns a char* array of the text that the string stores, which should be perfectly fine for what you are doing.

Share this post


Link to post
Share on other sites
thanks all - every comment seems to help - silver do you mean that it turns each character in a string to an elemnt ina char array? is there a reverse method?

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!