home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / win32-winerror.adb < prev    next >
Encoding:
Text File  |  1995-12-27  |  2.7 KB  |  86 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/win32-winerror.adb,v $ 
  2. -- $Revision: 1.4 $ $Date: 95/02/02 15:58:37 $ $Author: mg $ 
  3. -------------------------------------------------------------------------------
  4. --
  5. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT 
  6. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
  7. -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR 
  8. -- PURPOSE.  The user assumes the entire risk as to the accuracy and the 
  9. -- use of this file.
  10. --
  11. -- Copyright (c) Intermetrics, Inc. 1995
  12. -- Royalty-free, unlimited, worldwide, non-exclusive use, modification, 
  13. -- reproduction and further distribution of this file is permitted.
  14. --
  15. -------------------------------------------------------------------------------
  16.  
  17.  
  18. with Ada.Unchecked_Conversion;
  19. with Interfaces.C;
  20. with Interfaces;
  21. with Win32.Utils;
  22.  
  23. package body Win32.Winerror is
  24.  
  25.     use type Interfaces.C.Unsigned_Long;
  26.  
  27.     function SUCCEEDED(Status: HRESULT) return Standard.Boolean is
  28.         use Win32.Utils;
  29.     begin
  30.         return (Status >= 0);
  31.     end SUCCEEDED;
  32.  
  33.     function FAILED(Status: HRESULT) return Standard.Boolean is
  34.         use Win32.Utils;
  35.     begin
  36.         return not SUCCEEDED(Status);
  37.     end FAILED;
  38.  
  39.     function HRESULT_CODE(H: HRESULT) return WORD is 
  40.         use Win32.Utils;
  41.     begin
  42.         return Win32.Utils.LOWORD(Win32.Utils.DWORD(H));
  43.     end HRESULT_CODE;
  44.  
  45.     function HRESULT_FACILITY(H: HRESULT) return WORD is 
  46.         use Interfaces.C;
  47.     begin
  48.         return Win32.Utils.HIWORD(Win32.Utils.DWORD(H)) and 16#1fff#;
  49.     end HRESULT_FACILITY;
  50.  
  51.     function HRESULT_SEVERITY(H: HRESULT) return WORD is 
  52.     begin
  53.         if H < 0 then return 1; else return 0; end if;
  54.     end HRESULT_SEVERITY;
  55.  
  56.     function MAKE_HRESULT(sev,fac,code: WORD) return HRESULT is
  57.         use Win32.Utils;
  58.         use Interfaces;
  59.     begin
  60.         return HRESULT(
  61.         Shift_Left(Unsigned_32(sev), 31) or
  62.         Shift_Left(Unsigned_32(fac), 16) or
  63.         Unsigned_32(LONG(code)));
  64.     end MAKE_HRESULT;
  65.  
  66.     function HRESULT_FROM_WIN32(X: DWORD) return HRESULT is
  67.         use Win32.Utils;
  68.     use type Interfaces.C.Unsigned_Short;
  69.     begin
  70.         if X /= 0 then
  71.             return HRESULT(Win32.Utils.MAKELONG (
  72.                 Low  => LOWORD(X), 
  73.                 High => FACILITY_WIN32 or 16#8000#));
  74.         else
  75.             return 0;
  76.         end if;
  77.     end HRESULT_FROM_WIN32;
  78.  
  79.     function HRESULT_FROM_NT(X: DWORD) return HRESULT is
  80.         use Interfaces.C;
  81.     begin
  82.         return HRESULT(X or FACILITY_NT_BIT);
  83.     end HRESULT_FROM_NT;
  84.  
  85. end Win32.Winerror;
  86.