使用 ICU_REJECT_USERPWD 标志集调用 WinHttpCreateUrl 在 Windows 7 中工作,但在 Windows XP 中不起作用(使用虚拟 PC)

发布于 2024-11-19 14:34:59 字数 1256 浏览 6 评论 0原文

在 Windows XP 中(在 Windows 7 的 Virtual PC 下)运行我正在开发的应用程序时,我遇到了意外错误。我正在 Windows 7 64 位专业版中使用 Visual Studio 2010 编译它。

我已将问题归结为在 XP 下无法正确创建 URL。以下是我整理的一个小测试台来展示这一点 -

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 );
}

我希望它将 len 设置为正确的大小,并给出错误代码 0x7A 来指示 >ERROR_INSUFFICIENT_BUFFER。这就是 Windows 7 下发生的情况。在 Windows XP 下我实际上得到的是 0x57 错误代码,表示 ERROR_INVALID_PARAMETER

如果我将flags的值设置为,那么它在两个操作系统上都可以正常工作。我试图找出为什么 ICU_REJECT_USERPWD 导致它在 XP 下失败。

我意识到我不需要为此示例设置该标志,但这只是我为了显示问题而组合在一起的一些测试代码。

非常感谢您对这个问题的任何帮助(或任何指出我做错了什么的人......)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贱人配狗天长地久 2024-11-26 14:34:59

如果将components.nScheme 设置为INTERNET_SCHEME_HTTP,将components.nPort 设置为80 会怎样?例如,文档仅指定字符串点可以为 NULL,并且 0 不会映射到 nScheme 的有效值。

另外,当您设置 dwSchemeLength 和 dwHostNameLength 时,包含终止 NULL 是不一致的。我不确定你是否真的应该这样做;文档似乎没有指定,但我猜可能没有。

如果将 dwSchemeLength 设置为 4,将 dwHostNameLength 设置为 10 会怎样?如果这不起作用,请尝试将它们设置为 5 和 11。

我的猜测是结构不太正确;这可能有助于入门。

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.

无声静候 2024-11-26 14:34:59

我无法让 WinHttpCrackURL 在 XP 上使用 ICU_REJECT_PASSWORD 标志。
从 msdn 示例开始
http://msdn.microsoft.com/en- us/library/aa384092(v=vs.85).aspx

如果设置缓冲区,ICU_DECODE 和 ICU_ESCAPE 可以正常工作。
然而,传入 ICU_REJECT_PASSWORD 总是会导致失败,并且 GetLastError 返回 0x00000057,即 ERROR_INVALID_PARAMETER。

我猜测,尽管文档上有说明,XP 实际上并不支持该标志。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文