Hey guys,
I find it hard to understand what exactly with the below code.
even copy pasted from the book which im using to learn, same wrong output.
Code:
#include <windows.h>
#include <strsafe.h>
#include <wchar.h>
int wmain(void) {
wchar_t str[] = L"ZetCode";
size_t target_size = 0;
size_t size = sizeof(str);
HRESULT r = StringCbLengthW(str, size, &target_size);
if (SUCCEEDED(r)) {
wprintf(L"The string has %lld bytes\n", target_size);
} else {
wprintf(L"StringCbLengthW() failed\n");
return 1;
}
size = sizeof(str)/sizeof(wchar_t);
r = StringCchLengthW(str, size, &target_size);
if (SUCCEEDED(r)) {
wprintf(L"The string has %lld characters\n", target_size);
} else {
wprintf(L"StringCchLengthW() failed\n");
return 1;
}
return 0;
}
my output when i run is
The string has 28429359194832910 bytes
The string has 28429359194832903 characters
Press any key to continue...
whereas the output according to book and what i read in the MSDN documentation should be
The string has 14 bytes
The string has 7 characters
Note that i even copy pasted the code from book,, still got a wrong output. where did i go wrong?