Sign in to follow this  
Harryu

[SOLVED] wsprintf problems

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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);


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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