BOOL ErrorOut(HWND hErr, DWORD dwError)
{
int response;
TCHAR szTemp[356] = "", *szBuffer=NULL, *szBufferFinal = NULL;
DWORD dwIntError , dwLength = 0;
char strName[256]="";
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, GetModuleHandle("wininet.dll"),dwError,0,(LPSTR)strName,256,NULL);
wsprintf (szTemp, "error code: %d\nMessage: %s\n", dwError, strName);
if (dwError == ERROR_INTERNET_EXTENDED_ERROR) {
InternetGetLastResponseInfo (&dwIntError, NULL, &dwLength);
if (dwLength) {
if ( !(szBuffer = (TCHAR *) LocalAlloc ( LPTR, dwLength) ) ) {
lstrcat (szTemp, TEXT ( "Unable to allocate memory to display Internet error code. Error code: ") );
lstrcat (szTemp, TEXT (_itoa (GetLastError(), szBuffer, 10) ) );
lstrcat (szTemp, TEXT ("\n") );
response = MessageBox(hErr, (LPSTR)szTemp,"Error",MB_OK);
return FALSE;
}
if (!InternetGetLastResponseInfo (&dwIntError, (LPTSTR) szBuffer, &dwLength)) {
lstrcat (szTemp, TEXT ( "Unable to get Internet error. Error code: ") );
lstrcat (szTemp, TEXT (_itoa (GetLastError(), szBuffer, 10) ) );
lstrcat (szTemp, TEXT ("\n") );
response = MessageBox(hErr, (LPSTR)szTemp,"Error",MB_OK);
return FALSE;
}
if ( !(szBufferFinal = (TCHAR *) LocalAlloc ( LPTR, (strlen (szBuffer) +strlen (szTemp) + 1) ) ) ) {
lstrcat (szTemp, TEXT ( "Unable to allocate memory. Error code: ") );
lstrcat (szTemp, TEXT (_itoa (GetLastError(), szBuffer, 10) ) );
lstrcat (szTemp, TEXT ("\n") );
response = MessageBox(hErr, (LPSTR)szTemp,"Error",MB_OK);
return FALSE;
}
lstrcpy (szBufferFinal, szTemp);
lstrcat (szBufferFinal, szBuffer);
LocalFree (szBuffer);
response = MessageBox(hErr, (LPSTR)szBufferFinal,"Error",MB_OK);
LocalFree (szBufferFinal);
}
} else {
response = MessageBox(hErr, (LPSTR)szTemp,"Error",MB_OK);
}
return response;
}