Proper way of converting int to LPCWSTR (Win32)

11,244

Solution 1

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

Solution 2

_itow_s

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

Share:
11,244
Daniel Goldberg
Author by

Daniel Goldberg

I play around with computers, mainly Windows.

Updated on June 04, 2022

Comments

  • Daniel Goldberg
    Daniel Goldberg about 2 years

    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?

  • Matteo Italia
    Matteo Italia about 14 years
    In which way it doesn't fully solve your problem? By the way, you'd better use the more secure (and still standard) wsnprintf.