Trouble adding LPSTRs

Started by
3 comments, last by Xpyder 18 years, 10 months ago
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?
JUST-CODE-IT.NETManaged DirectX & C# TutorialsForumsArticlesLinksSamples
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();

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!
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.
my siteGenius is 1% inspiration and 99% perspiration
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?
JUST-CODE-IT.NETManaged DirectX & C# TutorialsForumsArticlesLinksSamples

This topic is closed to new replies.

Advertisement