0

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 problem (or to anyone who points out what I'm doing wrong...)

Rok
  • 2,568
  • 4
  • 26
  • 28

2 Answers2

1

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.

James Johnston
  • 9,264
  • 9
  • 48
  • 76
  • Well spotted with the **dwSchemeLength**! That wasn't the problem but it did need fixing (I was using https in my actual app and hadn't changed the length properly for the example). I've added the extra structure elements to the question now for completion (they were already in my main app but I removed them - probably unwisely - to make the example clearer). Good suggestion about trying it with the lengths set to include the null terminators but, unfortunately, it didn't solve the problem. I also think it must be something to do with the structure but can't see what that might be. – Rok Jul 12 '11 at 19:26
  • 1
    OK, next idea: MSDN documentation provides a sample that first cracks the URL, and then creates it from the cracked URL: http://msdn.microsoft.com/en-us/library/aa384093(VS.85).aspx. What happens if you modify this sample to use the flags you want? If the sample works, examine the cracked URL structure to see where the differences lie. – James Johnston Jul 12 '11 at 20:11
  • That was a great idea. It doesn't even work in the sample though when ICU_REJECT_PASSWORD is set. Fails if you try to get the buffer size and/or fails if you try to build the URL. Looks like that flag just isn't XP compatible. – Rok Jul 13 '11 at 08:09
0

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.

David Woo
  • 749
  • 4
  • 13
  • I tried the MSDN example code, too. Works fine on Windows 7 with the ICU_REJECT_PASSWORD flag but fails miserably under XP. I'll have to agree that it just doesn't work under XP. – Rok Jul 13 '11 at 08:11