Platform SDK: Windows Networking |
Windows NT/Windows 2000
The WNet functions return error codes for compatibility with Windows for Workgroups. For compatibility with the Win32 API, the function also sets the error code value returned by GetLastError.
When one of the WNet functions returns ERROR_EXTENDED_ERROR, an application can call the WNetGetLastError function to retrieve additional information about the error. This information is usually specific to the network provider.
The following example illustrates an application-defined error-handling function (NetErrorHandler). The function takes three arguments: a window handle, the error code returned by one of the WNet functions, and the name of the function that produced the error. If the error code is ERROR_EXTENDED_ERROR, NetErrorHandler calls WNetGetLastError to get extended error information and prints the information. The sample calls the MessageBox function to process messages.
BOOL WINAPI NetErrorHandler(HWND hwnd, DWORD dwErrorCode, LPSTR lpszFunction) { DWORD dwWNetResult, dwLastError; CHAR szError[256]; CHAR szCaption[256]; CHAR szDescription[256]; CHAR szProvider[256]; // The following code performs standard error-handling. if (dwErrorCode != ERROR_EXTENDED_ERROR) { wsprintf((LPSTR) szError, "%s failed; \nResult is %ld", lpszFunction, dwErrorCode); wsprintf((LPSTR) szCaption, "%s error", lpszFunction); MessageBox(hwnd, (LPSTR) szError, (LPSTR) szCaption, MB_OK); return TRUE; } // The following code performs error-handling when the // ERROR_EXTENDED_ERROR return value indicates that the // WNetGetLastError function can retrieve additional information. else { dwWNetResult = WNetGetLastError(&dwLastError, // error code (LPSTR) szDescription, // buffer for error description sizeof(szDescription), // size of error buffer (LPSTR) szProvider, // buffer for provider name sizeof(szProvider)); // size of name buffer // // Process errors. // if(dwWNetResult != NO_ERROR) { wsprintf((LPSTR) szError, "WNetGetLastError failed; error %ld", dwWNetResult); MessageBox(hwnd, (LPSTR) szError, "WNetGetLastError", MB_OK); return FALSE; } // // Otherwise, print the additional error information. // wsprintf((LPSTR) szError, "%s failed with code %ld;\n%s", (LPSTR) szProvider, dwLastError, (LPSTR) szDescription); wsprintf((LPSTR) szCaption, "%s error", lpszFunction); MessageBox(hwnd, (LPSTR) szError, (LPSTR) szCaption, MB_OK); return TRUE; } }