[b]procedure[/b] RaiseLastError;
[b]function[/b] EnumThreadWndProc(wnd: HWND; ResultWnd: PInteger): Boolean; [b]stdcall[/b];
[b]begin[/b]
Result := False;
ResultWnd^ := wnd;
[b]end[/b];
[b]var[/b]
ThreadId: Cardinal;
hWnd: Cardinal;
LastError: DWORD;
szBuffer, szError : [b]array[/b][0..255] [b]of[/b] Char;
[b]begin[/b]
ThreadID := GetCurrentThreadId;
EnumThreadWindows(ThreadID, @EnumThreadWndProc, Integer(@hWnd));
hWnd := GetLastActivePopup(hWnd);
LastError := GetLastError;
wvsprintf(szBuffer, '
Win32-Fehler. Code: %d', PChar(@LastError));
lstrcat(szBuffer, #13#10);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, [b]nil[/b], GetLastError, 0, szError,
sizeof(szError), [b]nil[/b]);
lstrcat(szBuffer, szError);
MessageBox(hWnd, szBuffer, 'Fehler', MB_ICONSTOP [b]or[/b] MB_APPLMODAL);
[b]end[/b];