Pascal Scripting: DLLGetLastError


function DLLGetLastError(): Longint;


Returns value the last error code had right after the most recent DLL function call you made. Useful after calling Windows API functions (if the function sets the last error code).


It's recommended to use this function instead of directly calling the GetLastError Windows API function since Setup or Uninstall makes API calls of its own, so the last error code could be overwritten at any time.

Refer to the system error codes on MSDN [external link].

function MessageBox(hWnd: Integer; lpText, lpCaption: AnsiString; uType: Cardinal): Integer; external 'MessageBoxA@user32.dll stdcall';


  if MessageBox(-1, '', '', -1) = 0 then
    MsgBox(SysErrorMessage(DLLGetLastError), mbError, mb_Ok);