home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / program3 / os2def.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-23  |  16KB  |  472 lines

  1. {***************************************************************************\
  2. *
  3. * Module Name: OS2DEF.H
  4. *
  5. * OS/2 Common Definitions file
  6. *
  7. * Copyright (c) International Business Machines Corporation 1981, 1988, 1989
  8. * Copyright (c) Microsoft Corporation 1981, 1988, 1989
  9. *
  10. \**************************************************************************}
  11.  
  12. {| Version:   1.02
  13.  | Original translation: Peter Singer (PSi)
  14.  | Contributing:
  15.  |   Peter Singer (PSi)
  16.  |   Peter Sawatzki (ps)
  17.  |
  18.  | change history:
  19.  | Date:    Ver: Author:
  20.  | 11/08/93 1.00 PSi    original translation by PSi
  21.  | 11/10/93 1.01 ps     added Inline macros
  22.  | 11/11/93 1.02 ps     correct some bugs
  23. }
  24. {$Define USE13}
  25. { Comments:
  26.   search for '***MC' for unresolved macros
  27.   search for '***TC' for unresolved types and constants
  28.   search for '-UNSURE-' for possibly incorrect translations
  29.   search for '-CANT-' for types that can't be translated correctly
  30. }
  31. Unit Os2Def;
  32. Interface
  33. type
  34.      SHANDLE    = word;
  35.      LHANDLE    = pointer;
  36.      Long       = LongInt;                {-ps-}
  37.  
  38. {***TC #define EXPENTRY pascal far _loadds
  39. ***TC #define APIENTRY pascal far}
  40.  
  41.      UCHAR      = Byte;
  42.      USHORT     = Word;
  43.      SHORT      = Integer;
  44.      UINT       = Word;
  45.      ULONG      = Longint;
  46.      BOOL       = {$IfDef Use13} WordBool {$Else} LongInt {$EndIf}; {-ps-}
  47.  
  48. { define NULL pointer value }
  49. { Echo the format of the ifdefs that stdio.h uses }
  50.  
  51. CONST NULL      = 0;
  52.  
  53.  
  54. type PSZ        = pChar;                       {-ps-}
  55.      NPSZ       = PSZ;      {-CANT-}           {-ps-}
  56.      PCH        = Pointer;
  57.      NPCH       = Pointer;  {-CANT-}
  58.  
  59. {typedef int   (pascal far  *PFN)();
  60.  typedef int   (pascal near *NPFN)();}
  61.   pFn = Function: Integer;                     {-ps-}
  62.   npFn = Function: Integer;  {-CANT-}          {-ps-}
  63.  
  64.      PBYTE      = ^Byte;                       {-ps-}
  65.      NPBYTE     = ^Byte;     {-CANT-}          {-ps-}
  66. {    PCHAR      = Pointer;}                    {-ps-}
  67.      PSHORT     = ^Integer;                    {-ps-}
  68.      PLONG      = ^Longint;                    {-ps-}
  69.      PINT       = ^Integer;                    {-ps-}
  70.      PUCHAR     = PChar;                       {-ps-}
  71.      PUSHORT    = PSHORT;                      {-ps-}
  72.      PULONG     = PLONG;                       {-ps-}
  73.      PUINT      = ^Word;
  74.      PVOID      = Pointer;
  75.      PBOOL      = ^Boolean;                    {-ps-}
  76.  
  77. CONST
  78.      FALSE      = BOOL(0);
  79.      TRUE       = BOOL(1);
  80.  
  81. Type
  82.     SEL         = Word;
  83.     PSEl        = Pointer;
  84.  
  85. Const
  86.   PopAx = $58;
  87.   PopDx = $5A;
  88.   PopBx = $5B;
  89. {** Useful Helper Macros }
  90.  
  91. { Create untyped far pointer from selector and offset }
  92. {#define MAKEP(sel, off)     ((PVOID)MAKEULONG(off, sel))}
  93. Function MakeP(Sel,Off: Word): Pointer;        {-ps-}
  94.   Inline(PopAx/PopDx);                         {-ps-}
  95.  
  96. { Extract selector or offset from far pointer }
  97. {#define SELECTOROF(p)       (((PUSHORT)&(p))[1])}
  98. {#define OFFSETOF(p)         (((PUSHORT)&(p))[0])}
  99. Function SelectorOf(p: Pointer): Word;         {-ps-}
  100.   Inline(PopDx/PopAx);                         {-ps-}
  101.  
  102. Function OffsetOf(p: Pointer): Word;           {-ps-}
  103.   Inline(PopAx/PopDx);                         {-ps-}
  104.  
  105. { Cast any variable to an instance of the specified type. }
  106. {***MC #define MAKETYPE(v, type)   (*((type far *)&v))}
  107.  
  108. { Calculate the byte offset of a field in a structure of type type. }
  109. {#define FIELDOFFSET(type, field)    ((SHORT)&(((type *)0)->field))}
  110. {instead of the type of the structure, we pass the structure itself -PS}
  111. Function FieldOffset (Var Structure; Var Field): Word;            {-ps-}
  112.   Inline(PopBx/PopDx/PopAx/PopDx/ $29/$D8 {Sub Ax,Bx});           {-ps-}
  113.  
  114. { Combine l & h to form a 32 bit quantity. }
  115. {#define MAKEULONG(l, h)  ((ULONG)(((USHORT)(l)) | ((ULONG)((USHORT)(h))) << 16))}
  116. {#define MAKELONG(l, h)   ((LONG)MAKEULONG(l, h))}
  117. Function MakeLong(L, H: Word): Long;           {-ps-}
  118.   Inline(PopDx/PopAx);                         {-ps-}
  119.  
  120. Function MakeULong(L, H: Word): ULong;         {-ps-}
  121.   Inline(PopDx/PopAx);                         {-ps-}
  122.  
  123. { Combine l & h to form a 16 bit quantity. }
  124. {#define MAKEUSHORT(l, h) (((USHORT)(l)) | ((USHORT)(h)) << 8)}
  125. {#define MAKESHORT(l, h)  ((SHORT)MAKEUSHORT(l, h))}
  126. Function MakeShort (l,h: Byte): Short;                        {-ps-}
  127.   Inline(PopBx/PopAx/ $88/$DC {Mov Ah,Bl});                   {-ps-}
  128.  
  129. Function MakeUShort (l,h: Byte): UShort;                      {-ps-}
  130.   Inline(PopBx/PopAx/ $88/$DC {Mov Ah,Bl});                   {-ps-}
  131.  
  132. { Extract high and low order parts of 16 and 32 bit quantity }
  133. {#define LOBYTE(w)       LOUCHAR(w)                           }
  134. {#define HIBYTE(w)       HIUCHAR(w)                           }
  135. {#define LOUCHAR(w)      ((UCHAR)(w))                         }
  136. {#define HIUCHAR(w)      ((UCHAR)(((USHORT)(w) >> 8) & 0xff)) }
  137. {#define LOUSHORT(l)     ((USHORT)(l))                        }
  138. {#define HIUSHORT(l)     ((USHORT)(((ULONG)(l) >> 16) & 0xffff))}
  139. Function LoByte(w: Word): Byte;                                    {-ps-}
  140.   Inline(PopAx / $32/$E4 {Xor Ah,Ah});                             {-ps-}
  141. Function LoUByte(w: Word): UChar;                                  {-ps-}
  142.   Inline(PopAx / $32/$E4 {Xor Ah,Ah});                             {-ps-}
  143.  
  144. Function HiByte(w: Word): Byte;                                    {-ps-}
  145.   Inline(PopAx / $8A/$C4 {Mov Al,Ah} / $32/$E4 {Xor Ah,Ah});       {-ps-}
  146. Function HiUChar(w: Word): UChar;                                  {-ps-}
  147.   Inline(PopAx / $8A/$C4 {Mov Al,Ah} / $32/$E4 {Xor Ah,Ah});       {-ps-}
  148.  
  149. Function LoUShort(l: Long): UShort;                                {-ps-}
  150.   Inline(PopAx/PopDx);                                             {-ps-}
  151. Function HiUShort(l: Long): UShort;                                {-ps-}
  152.   Inline(PopDx/PopAx);                                             {-ps-}
  153.  
  154. {** Common Error definitions ***}
  155.  
  156. type
  157.      ERRORID    = Longint;   { ULONG ERRORID}
  158.      PERRORID   = Pointer;
  159.  
  160. { Combine severity and error code to produce ERRORID }
  161. {#define MAKEERRORID(sev, error) (ERRORID)(MAKEULONG((error), (sev)))}
  162. Function MakeErrorId(sev, error: UShort): ERRORID;          {-ps-}
  163.   Inline(PopDx/PopAx);                                      {-ps-}
  164. { Extract error number from an errorid }
  165. {#define ERRORIDERROR(errid)            (LOUSHORT(errid))}
  166. Function ErrorIdError(errid: ERRORID): UShort;              {-ps-}
  167.   Inline(PopAx/PopDx);                                      {-ps-}
  168. { Extract severity from an errorid }
  169. {#define ERRORIDSEV(errid)              (HIUSHORT(errid))}
  170. Function ErrorIdSev(errid: ERRORID): UShort;                {-ps-}
  171.   Inline(PopDx/PopAx);                                      {-ps-}
  172.  
  173. { Severity codes }
  174. CONST
  175.       SEVERITY_NOERROR         = $0000;
  176.       SEVERITY_WARNING         = $0004;
  177.       SEVERITY_ERROR           = $0008;
  178.       SEVERITY_SEVERE          = $000C;
  179.       SEVERITY_UNRECOVERABLE   = $0010;
  180.  
  181. { Base component error values }
  182.  
  183.       WINERR_BASE              = $1000;  { Window Manager                  }
  184.       GPIERR_BASE              = $2000;  { Graphics Presentation Interface }
  185.       DEVERR_BASE              = $3000;  { Device Manager                  }
  186.       SPLERR_BASE              = $4000;  { Spooler                         }
  187.  
  188. {** Common types used across components }
  189.  
  190. {** Common DOS types }
  191.  
  192. Type
  193.     HMODULE             = {$IfDef Use13} Word {$Else} LongInt {$EndIf};
  194.     PHMODULE            = ^HMODULE;
  195.     PID                 = {$IfDef Use13} Word {$Else} LongInt {$EndIf};
  196.     PPID                = ^PID;
  197.     TID                 = {$IfDef Use13} Word {$Else} LongInt {$EndIf};
  198.     PTID                = ^TID;
  199.     HSEM                = Pointer;                     { hsem }
  200.     PHSEM               = ^HSEM;
  201.  
  202. {** Common SUP types }
  203.  
  204.     HAB                 = LHANDLE;      { hab  }
  205.     PHAB                = ^HAB;
  206.  
  207. {** Common GPI/DEV types }
  208.  
  209.     HPS                 = LHANDLE;      { hps  }
  210.     PHPS                = ^HPS;
  211.  
  212.     HDC                 = LHANDLE;