Search code examples
c++stringwindows-cezune

Construct a LPCWSTR on WinCE in C++ (Zune/ZDK)


What's a good way to construct an LPCWSTR on WinCE 6? I'd like to find something similar to String.Format() in C#. My attempt is:

OSVERSIONINFO   vi;

memset (&vi, 0, sizeof vi);
vi.dwOSVersionInfoSize = sizeof vi;
GetVersionEx (&vi);

char buffer[50];
int n = sprintf(buffer, "The OS version is: %d.%d", vi.dwMajorVersion, vi.dwMinorVersion);

ZDKSystem_ShowMessageBox(buffer, MESSAGEBOX_TYPE_OK);

That ZDKSystem_ShowMessageBox refers to the ZDK for hacked Zunes available at: http://zunedevwiki.org

This line of code works well with the message box call:

ZDKSystem_ShowMessageBox(L"Hello Zune", MESSAGEBOX_TYPE_OK);

My basic goal is to look at the exact version of WinCE running on a Zune HD to see which features are available (i.e. is it R2 or earlier?).

Also I haven't seen any tags for the ZDK so please edit if something is more fitting!


Solution

  • sprintf is for narrow strings. LPCWSTR is a const WCHAR *, so you need wide characters, and the right function.

    E.g.

    WCHAR buf[100];
    StringCchPrintfW(buf, _countof(buf), L"Hello, world!");
    

    or using generic text functions, and compiling with UNICODE,

    TCHAR buf[100];
    StringCchPrintf(buf, _countof(buf), _T("Hello, world!"));
    

    (There are other functions you could use, such as _stprintf_s, swprintf_s, etc)