views:

1397

answers:

4

I'm attempting to learn basic Win32 programming and running into a frustrating problem. I wish to convert a variable (Call it NumClicks) and display it as the application name (as part of a string). From what I've seen, going from int + some block of text to a char* is problematic, because converting it to the requisite end data type(LPCWSTR) is more difficult than a straight casting.

Any ideas or links?

+5  A: 

use wsprintf
It allows you to compose a string the same way printf allows you to print a line of text.

shoosh
Doesn't fully solve my problem.
Daniel Goldberg
In which way it doesn't fully solve your problem? By the way, you'd better use the more secure (and still standard) wsnprintf.
Matteo Italia
+3  A: 

_itow_s

If you're looking for more than just INT to LPWSTR conversion (such as formatting), I'd suggest StringCchPrintfW.

Irwin
A: 

rather than use wsprintf i would use sprinf(buf, "%S", "plain old string");

With the result that you don't get a wide string, which instead is what he need (LPCWSTR = const __wchar_t__ *).
Matteo Italia
A: 

Here is the code I used, when I needed LPCWSTR:


int f =55;  
wchar_t buffer[10];
_itow_s (f, buffer, 10);
func_using_lpcwstr_as_parameter(buffer);

watch for buffer overflows in this sample

TGadfly