Pascal Scripting: DLLGetLastError

Prototype:

function DLLGetLastError(): Longint;

Description:

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).

Remarks:

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].

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

...

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