When one of the Windows network functions returns WN_EXTENDED_ERROR, an application can call the WNetGetLastError function to retrieve more information about the error that occurred. This information is typically specific to the network provider.
The following code fragment is an error-handling function that takes three arguments: a window handle, the error code returned by one of the Windows network functions, and the name of the function that produced the error. If the error code is WN_EXTENDED_ERROR, the function calls WNetGetLastError to retrieve extended error information.
BOOL FAR PASCAL ErrorHandler(hwnd, dwErrorCode, lpszFunction)
HWND hwnd;
DWORD dwErrorCode;
LPSTR lpszFunction;
{
DWORD dwWNetResult, dwLastError;
CHAR achError[256];
CHAR achCaption[256];
CHAR achDescription[256];
CHAR achProvider[256];
if (dwErrorCode != ERROR_EXTENDED_ERROR) {
wsprintf((LPSTR) achError, "%s failed; \nResult is %ld",
lpszFunction, dwErrorCode);
wsprintf((LPSTR) achCaption, "%s error", lpszFunction);
MessageBox(hwnd, (LPSTR) achError, (LPSTR) achCaption, MB_OK);
return TRUE;
}
else {
dwWNetResult = WNetGetLastError(&dwLastError,
(LPSTR) achDescription, /* buffer for error description */
sizeof(achDescription),
(LPSTR) achProvider, /* buffer for provider name */
sizeof(achProvider));
if(dwWNetResult != NO_ERROR) {
wsprintf((LPSTR) achError,
"WNetGetLastError failed; error %ld", dwWNetResult);
MessageBox(hwnd, (LPSTR) achError, "WNetGetLastError", MB_OK);
return FALSE;
}
wsprintf((LPSTR) achError,
"%s failed with code %ld;\n%s",
(LPSTR) achProvider, dwLastError, (LPSTR) achDescription);
wsprintf((LPSTR) achCaption, "%s error", lpszFunction);
MessageBox(hwnd, (LPSTR) achError, (LPSTR) achCaption, MB_OK);
return TRUE;
}
}