Re:What the L? in wsprintf
Quote
>
>Others I have talked to don't even use the L, so why do I seem to need
>it. Why does it not display integers correctly? And what does it mean?
L"" defines a wide-character (i.e. Unicode) string literal, while ""
defines an MBCS (i.e. ANSI) string literal.
Whether you need to use a wide-character string in a call to wsprintf
depends on whether you're doing a UNICODE build or an ANSI build. The
easiest way to get the right kind of string literal when working with
TCHAR and related functions (like wsprintf) is to use the _T macro:
wsprintf(pelement->string, _T("%d"), (UINT32)val);
wsprintf(pelement->string,_T("%s"), _T("test"));
By the way, how is pelement->string declared?
Finally, consider not using wsprintf: it's vulnerable to buffer overrun
problems and is non-standard. Consider using _sntprintf or _sntprintf_s
instead.
Here is a little background on what I'm doing. I am programming a aircraft
panel gauge for MS Flight Simulator. The wsprintf is used in a callback
routine set up by a FS macro. The callback looks like this:
FLOAT64 FSAPI update_callback(PELEMENT_STRING pelement ){
FLOAT64 val=pelement->source_var[0].var_value.n;
wsprintf(pelement->string, L"%d",(UINT32)val);
return val;
}
I've presented this problem to the FS programming forums and no one even
uses the L. Their routines look exactly like mine but use "%3d" instead of
L"%d", but that doesn't work for me.
I tried what you suggested and here are my results. When I use:
wsprintf(pelement->string, _T("%d"), (UINT32)val);
I get "warning C4013: '_T' undefined; assuming extern returning int"
When I use:
_sntprintf(pelement->string, _T("%d"), (UINT32)val);
I get:
warning C4013: '_sntprintf' undefined; assuming extern returning int
warning C4013: '_T' undefined; assuming extern returning int
Am I not setting something right in my programming enviroment?
Thomas
-