Is it OK to pass NULL as the first argument to WindowsDuplicateString? The documentation isn't clear here but calling WindowsCreateString(NULL, 0, &s) is allowed and my tests showed that it sets s to NULL so NULL seems to be a valid HSTRING. Other functions like WindowsGetStringLen also allow passing a NULL HSTRING.
2 Answers
so
NULLseems to be a validHSTRING.
This is not something that needs to be guessed at, as Microsoft has documented it:
Semantically, an HSTRING containing the value NULL represents the empty string, which consists of zero content characters and a terminating NULL character. Creating a string via WindowsCreateString with zero characters will produce the handle value NULL.
Since NULL is documented to be a valid HSTRING, one may assume that it is valid for WindowsDuplicateString in the absence of documentation to the contrary (unless you believe the documentation is incomplete, in which case all bets are off).
Comments
if look for declaration of WindowsDuplicateString from winstring.h
STDAPI
WindowsDuplicateString(
_In_opt_ HSTRING string,
_Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING* newString
);
visible that first argument declared as _In_opt_ so it allowed to got 0 as string
STDAPI_(UINT32)
WindowsGetStringLen(
_In_opt_ HSTRING string
);
so this api also allowed get NULL (0) as string
S_OKwhen I tested it.