大网数据广告活动
账户与安全

Returning Values to the MPR

· 52CE 我爱测

The Windows Networking functions return WN_SUCCESS on success, or they return a unique nonzero value if the function encounters an error. In addition, they return extended error information using WNetSetLastError and SetLastError.

The Windows Networking functions return WN_SUCCESS on success, or they return a unique nonzero value if the function encounters an error. In addition, they return extended error information using WNetSetLastError and SetLastError.

To support the above behavior, network provider functions should not call SetLastError before returning. This is because the MPR calls SetLastError for the functions in the Network Provider API after they return. If the network providers call SetLastError directly, they will be making redundant function calls. Network provider functions should simply return an error code. The error codes are specified in the function description or Return Values. Also, network provider functions may return any System Error Codes, such as insufficient memory. The only exception is NPGetCaps, which should return a mask indicating the functions supported by the network provider.

If a network provider function needs to return extended error information, it should call WNetSetLastError. This function is provided by the Windows operating system for use by network providers. When the provider calls WNetSetLastError, it can set a string containing additional information about the error. This information is stored on a per-thread basis. This is analogous to SetLastError for Windows applications. The Windows operating system calls WNetSetLastError to check for a string stored using WNetSetLastError and, if found, returns the extended error information to the calling application that initiated the network request.

Note:
The WNet prefix of WNetSetLastError is misleading since this API, unlike WNetSetLastError, is not part of the Windows Networking API set. WNetSetLastError is intended for use only by network providers. The name, WNetSetLastError, is retained for compatibility with existing providers.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。