2

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.

4
  • Check the function's return value - if it's S_OK I think you're good. Commented Sep 19 at 10:51
  • @500-InternalServerError it was S_OK when I tested it. Commented Sep 19 at 10:53
  • 1
    please tag your question with either c or c++. Commented Sep 19 at 12:43
  • @jorgeisnotai the question is relevant to both C and C++. Commented Oct 5 at 8:03

2 Answers 2

8

so NULL seems to be a valid HSTRING.

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).

Sign up to request clarification or add additional context in comments.

Comments

3

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

2 Comments

Look at this. It is not true.
@ImanAbdollahzadeh look to real header file better

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.