[SOLVED] wsprintf problems

Started by
1 comment, last by Harryu 17 years, 9 months ago
Ok. I am programming a 3D rpg in DirectX and C++. At the moment, I am experiencing a very annoying problem relating to the use of wsprintf. Basically, I call wsprintf like this: wsprintf(Text, "blahblahblah %d", Num); Which is how I think I'm meant to be doing it. The problem is, sometimes, as soon as the program reaches that point I get a non-responsive program error. It has happened many times throughout my game, and I've managed to find ways around it, but I can't think of a good way to get around this one. Especially when I don't even know what the problem is! So if anybody has any idea whatsoever what might cause wsprintf to cause my program to crash, please say so. Any help will be greatly appreciated. Harry [Edited by - Harryu on July 20, 2006 8:50:44 PM]
Advertisement
The w at the beginning stands for "wide". The function expects it's arguments to be made of wide characters (ie. Unicode more or less).

wsprintf(Text, "blahblahblah %d", Num);

String literals are ansi. Try wrapping the format spec in a _T macro (or TEXT macro if you prefer).

For example:

wsprintf(Text, _T("blahblahblah %d"), Num);


"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
when I try that I get a compiler error:

_T identifier not found

EDIT: Solved. For some reason I had declared Text as a pointer rather than just an array of chars. I don't know why it was fixed when I changed it, but it did. I'd still sort of like to know what the problem was if anybody has some ideas.

This topic is closed to new replies.

Advertisement