Call to WinHttpCreateUrl with ICU_REJECT_USERPWD flag set working in Windows 7 but not Windows XP (using Virtual PC)
I've been getting unexpected errors when running the app I'm developing in Windows XP (under Virtual PC from Windows 7). I'm compiling it using Visual Studio 2010 in Windows 7 64-bit Professional.
I've tracked the problem down to URLs not being created properly under XP. The following is a small test bed I put together to show this -
URL_COMPONENTS components;
memset( &components, 0, sizeof( URL_COMPONENTS ));
components.dwStructSize = sizeof( URL_COMPONENTS );
components.lpszScheme = L"http";
components.dwSchemeLength = 4;
components.lpszHostName = L"google.com";
components.dwHostNameLength = 10;
components.nScheme = INTERNET_SCHEME_HTTP;
components.nPort = 80;
DWORD len = 0;
DWORD flags = ICU_REJECT_USERPWD;
if( !WinHttpCreateUrl( &components, flags, NULL, &len )) {
WChar buf[256];
wsprintf( buf, L"Error code %08X", GetLastError( ));
MessageBox( NULL, buf, L"FAILURE", NULL );
}
I would expect it to set len to the correct size and give an error code of 0x7A to indicate ERROR_INSUFFICIENT_BUFFER. This is what happens under Windows 7. What I'm actually getting under Windows XP is an error code of 0x57 to indicate ERROR_INVALID_PARAMETER.
If I set the value of flags to be zero then it works fine on both Operating Systems. What I'm trying to work out is why ICU_REJECT_USERPWD is causing it to fail under XP.
I realise I don't need that flag to be set for this example, but this is just some test code I put together to display the issue.
Many thanks for any help with this proble开发者_高级运维m (or to anyone who points out what I'm doing wrong...)
What if you set components.nScheme to INTERNET_SCHEME_HTTP, and components.nPort to 80? The documentation only specifies that the string points may be NULL, and 0 does not map to a valid value for nScheme, for example.
Also, when you set dwSchemeLength and dwHostNameLength, you are inconsistent in including the terminating NULL. I am not sure if you are actually supposed to do this; the documentation does not seem to specify but I would guess maybe not.
What if you set dwSchemeLength to 4, and dwHostNameLength to 10? If that doesn't work, try setting them to 5 and 11.
My guess is things aren't quite right in the structure; this might help get started.
I can't get WinHttpCrackURL to work with the ICU_REJECT_PASSWORD flag on XP. Starting with the msdn example http://msdn.microsoft.com/en-us/library/aa384092(v=vs.85).aspx
ICU_DECODE and ICU_ESCAPE work fine if you set the buffers. However passing in ICU_REJECT_PASSWORD always results in a fail and GetLastError returns 0x00000057 which is ERROR_INVALID_PARAMETER.
I'm guessing that flag is not actually supported on XP despite what the documentation says.
精彩评论