printf/wprintf and wchar

I have PIMAGE_RESOURCE_DIR_STRING_U, let's call it pResDirStrU.
I want to print it's NameString field which is a wchar.

I tried
1
2
3
4
printf("Name: %s", pResDirStrU->NameString); // prints only the first character
printf("Name: %S", pResDisStrU->NameString); // prints more than it should
wprintf(L"Name: %s", pResDirStrU->NameString); 
// prints more than it should, but replaces gibberish / characters from another structure with "?" 


Now, what is the correct way of printing this?
I'm doing it like this
1
2
3
4
for(j = 0; j < resDirStrU->Length; j++)
{
    printf("%c", resDirStrU->NameString[j]);
}

But, you know, that doesn't look so nice.
Last edited on
It depends on the type and content of NameString. So, what is it?
NameString is defined in WinNT.h as a WCHAR.
It contains a UNICODE string (according to MSDN this is true even for non-UNICODE Win32 implementations).
When it prints more than it should there's probably a 0 at the end of the string missing.
So I have 2 choices:
print the characters one by one or
tell printf how much it should print.
or you can add the required 0
Topic archived. No new replies allowed.