Hi

I am trying to convert the outbuff from WinHttpQueryHeaders to string but its not working properly...

my code

if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER )
    {

        lpOutBuffer = new WCHAR[dwSize/sizeof(WCHAR)];

		
        // Now, use WinHttpQueryHeaders to retrieve the header.
        bResults = WinHttpQueryHeaders( hRequest, 
                                   WINHTTP_QUERY_RAW_HEADERS_CRLF,
                                   WINHTTP_HEADER_NAME_BY_INDEX, 
                                  lpOutBuffer, &dwSize, 
                                   WINHTTP_NO_HEADER_INDEX);

	


    }
}

string str=(char*)lpOutBuffer;

string just showing the 1st charecter "H" after that.

Thanks in advance

Hi

I am trying to convert the outbuff from WinHttpQueryHeaders to string but its not working properly...

my code

if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER )
    {

        lpOutBuffer = new WCHAR[dwSize/sizeof(WCHAR)];

		
        // Now, use WinHttpQueryHeaders to retrieve the header.
        bResults = WinHttpQueryHeaders( hRequest, 
                                   WINHTTP_QUERY_RAW_HEADERS_CRLF,
                                   WINHTTP_HEADER_NAME_BY_INDEX, 
                                  lpOutBuffer, &dwSize, 
                                   WINHTTP_NO_HEADER_INDEX);

	


    }
}

string str=(char*)lpOutBuffer;

string just showing the 1st charecter "H" after that.

Thanks in advance

The string assignment operator expects a null terminated character array. Meaning as soon as it sees a 0 value, it will stop. The extra bits in WCHAR probably contain a 0 after the H as padding, since it's unused. You'll need to find a way to convert WCHAR to char before trying to use the assignment operator like this. Or maybe you can use wstring. I try to stay away from that whole "wide" character mess, so I'm not the best one to ask... but now that you know what the problem is you probably know better than me how to fix it.
-Greywolf

thanks for replay , but i have already solved the problem using sprintf :D

This article has been dead for over six months. Start a new discussion instead.