dimanche 31 octobre 2021

sending a pointer of member of global variable to an WinHttpQueryHeaders does not change it's value

I have the following code snippet:

        // Using HttpQueryInfo to obtain the size of the buffer into dwSize.
        if (!WinHttpQueryHeaders(hRequest,
            WINHTTP_QUERY_RAW_HEADERS_CRLF,
            WINHTTP_HEADER_NAME_BY_INDEX, NULL, &st.dwSize, WINHTTP_NO_HEADER_INDEX))
        {
            // An ERROR_INSUFFICIENT_BUFFER is expected because you
            // are looking for the size of the headers.  If any other
            // error is encountered, display error information.
            DWORD dwErr = GetLastError();
            if (dwErr != ERROR_INSUFFICIENT_BUFFER)
            {
                DEBUG_PRINT(("Error %d encountered.", dwErr));
                return;
            } else {
                // enters here and prints '0' (initial value)
                DEBUG_PRINT(("size of buffer: ", &st.dwSize));
            }
        }

while st is a global object with a member dwSize.

When I'm running this part in debugging mode I see that dwSize does not change its value after the call to WinHttpQueryHeaders.

But if I create a local var DWORD dwSize = 0 and send &dwSize to WinHttpQueryHeaders, it does obtain buffer size and succeeds to change its value.

is there any reason why I shouldn't send a pointer of a global object's member to WinHttpQueryHeaders or to any other external API functions?

Aucun commentaire:

Enregistrer un commentaire