home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
program3
/
os2def.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-11-23
|
16KB
|
472 lines
{***************************************************************************\
*
* Module Name: OS2DEF.H
*
* OS/2 Common Definitions file
*
* Copyright (c) International Business Machines Corporation 1981, 1988, 1989
* Copyright (c) Microsoft Corporation 1981, 1988, 1989
*
\**************************************************************************}
{| Version: 1.02
| Original translation: Peter Singer (PSi)
| Contributing:
| Peter Singer (PSi)
| Peter Sawatzki (ps)
|
| change history:
| Date: Ver: Author:
| 11/08/93 1.00 PSi original translation by PSi
| 11/10/93 1.01 ps added Inline macros
| 11/11/93 1.02 ps correct some bugs
}
{$Define USE13}
{ Comments:
search for '***MC' for unresolved macros
search for '***TC' for unresolved types and constants
search for '-UNSURE-' for possibly incorrect translations
search for '-CANT-' for types that can't be translated correctly
}
Unit Os2Def;
Interface
type
SHANDLE = word;
LHANDLE = pointer;
Long = LongInt; {-ps-}
{***TC #define EXPENTRY pascal far _loadds
***TC #define APIENTRY pascal far}
UCHAR = Byte;
USHORT = Word;
SHORT = Integer;
UINT = Word;
ULONG = Longint;
BOOL = {$IfDef Use13} WordBool {$Else} LongInt {$EndIf}; {-ps-}
{ define NULL pointer value }
{ Echo the format of the ifdefs that stdio.h uses }
CONST NULL = 0;
type PSZ = pChar; {-ps-}
NPSZ = PSZ; {-CANT-} {-ps-}
PCH = Pointer;
NPCH = Pointer; {-CANT-}
{typedef int (pascal far *PFN)();
typedef int (pascal near *NPFN)();}
pFn = Function: Integer; {-ps-}
npFn = Function: Integer; {-CANT-} {-ps-}
PBYTE = ^Byte; {-ps-}
NPBYTE = ^Byte; {-CANT-} {-ps-}
{ PCHAR = Pointer;} {-ps-}
PSHORT = ^Integer; {-ps-}
PLONG = ^Longint; {-ps-}
PINT = ^Integer; {-ps-}
PUCHAR = PChar; {-ps-}
PUSHORT = PSHORT; {-ps-}
PULONG = PLONG; {-ps-}
PUINT = ^Word;
PVOID = Pointer;
PBOOL = ^Boolean; {-ps-}
CONST
FALSE = BOOL(0);
TRUE = BOOL(1);
Type
SEL = Word;
PSEl = Pointer;
Const
PopAx = $58;
PopDx = $5A;
PopBx = $5B;
{** Useful Helper Macros }
{ Create untyped far pointer from selector and offset }
{#define MAKEP(sel, off) ((PVOID)MAKEULONG(off, sel))}
Function MakeP(Sel,Off: Word): Pointer; {-ps-}
Inline(PopAx/PopDx); {-ps-}
{ Extract selector or offset from far pointer }
{#define SELECTOROF(p) (((PUSHORT)&(p))[1])}
{#define OFFSETOF(p) (((PUSHORT)&(p))[0])}
Function SelectorOf(p: Pointer): Word; {-ps-}
Inline(PopDx/PopAx); {-ps-}
Function OffsetOf(p: Pointer): Word; {-ps-}
Inline(PopAx/PopDx); {-ps-}
{ Cast any variable to an instance of the specified type. }
{***MC #define MAKETYPE(v, type) (*((type far *)&v))}
{ Calculate the byte offset of a field in a structure of type type. }
{#define FIELDOFFSET(type, field) ((SHORT)&(((type *)0)->field))}
{instead of the type of the structure, we pass the structure itself -PS}
Function FieldOffset (Var Structure; Var Field): Word; {-ps-}
Inline(PopBx/PopDx/PopAx/PopDx/ $29/$D8 {Sub Ax,Bx}); {-ps-}
{ Combine l & h to form a 32 bit quantity. }
{#define MAKEULONG(l, h) ((ULONG)(((USHORT)(l)) | ((ULONG)((USHORT)(h))) << 16))}
{#define MAKELONG(l, h) ((LONG)MAKEULONG(l, h))}
Function MakeLong(L, H: Word): Long; {-ps-}
Inline(PopDx/PopAx); {-ps-}
Function MakeULong(L, H: Word): ULong; {-ps-}
Inline(PopDx/PopAx); {-ps-}
{ Combine l & h to form a 16 bit quantity. }
{#define MAKEUSHORT(l, h) (((USHORT)(l)) | ((USHORT)(h)) << 8)}
{#define MAKESHORT(l, h) ((SHORT)MAKEUSHORT(l, h))}
Function MakeShort (l,h: Byte): Short; {-ps-}
Inline(PopBx/PopAx/ $88/$DC {Mov Ah,Bl}); {-ps-}
Function MakeUShort (l,h: Byte): UShort; {-ps-}
Inline(PopBx/PopAx/ $88/$DC {Mov Ah,Bl}); {-ps-}
{ Extract high and low order parts of 16 and 32 bit quantity }
{#define LOBYTE(w) LOUCHAR(w) }
{#define HIBYTE(w) HIUCHAR(w) }
{#define LOUCHAR(w) ((UCHAR)(w)) }
{#define HIUCHAR(w) ((UCHAR)(((USHORT)(w) >> 8) & 0xff)) }
{#define LOUSHORT(l) ((USHORT)(l)) }
{#define HIUSHORT(l) ((USHORT)(((ULONG)(l) >> 16) & 0xffff))}
Function LoByte(w: Word): Byte; {-ps-}
Inline(PopAx / $32/$E4 {Xor Ah,Ah}); {-ps-}
Function LoUByte(w: Word): UChar; {-ps-}
Inline(PopAx / $32/$E4 {Xor Ah,Ah}); {-ps-}
Function HiByte(w: Word): Byte; {-ps-}
Inline(PopAx / $8A/$C4 {Mov Al,Ah} / $32/$E4 {Xor Ah,Ah}); {-ps-}
Function HiUChar(w: Word): UChar; {-ps-}
Inline(PopAx / $8A/$C4 {Mov Al,Ah} / $32/$E4 {Xor Ah,Ah}); {-ps-}
Function LoUShort(l: Long): UShort; {-ps-}
Inline(PopAx/PopDx); {-ps-}
Function HiUShort(l: Long): UShort; {-ps-}
Inline(PopDx/PopAx); {-ps-}
{** Common Error definitions ***}
type
ERRORID = Longint; { ULONG ERRORID}
PERRORID = Pointer;
{ Combine severity and error code to produce ERRORID }
{#define MAKEERRORID(sev, error) (ERRORID)(MAKEULONG((error), (sev)))}
Function MakeErrorId(sev, error: UShort): ERRORID; {-ps-}
Inline(PopDx/PopAx); {-ps-}
{ Extract error number from an errorid }
{#define ERRORIDERROR(errid) (LOUSHORT(errid))}
Function ErrorIdError(errid: ERRORID): UShort; {-ps-}
Inline(PopAx/PopDx); {-ps-}
{ Extract severity from an errorid }
{#define ERRORIDSEV(errid) (HIUSHORT(errid))}
Function ErrorIdSev(errid: ERRORID): UShort; {-ps-}
Inline(PopDx/PopAx); {-ps-}
{ Severity codes }
CONST
SEVERITY_NOERROR = $0000;
SEVERITY_WARNING = $0004;
SEVERITY_ERROR = $0008;
SEVERITY_SEVERE = $000C;
SEVERITY_UNRECOVERABLE = $0010;
{ Base component error values }
WINERR_BASE = $1000; { Window Manager }
GPIERR_BASE = $2000; { Graphics Presentation Interface }
DEVERR_BASE = $3000; { Device Manager }
SPLERR_BASE = $4000; { Spooler }
{** Common types used across components }
{** Common DOS types }
Type
HMODULE = {$IfDef Use13} Word {$Else} LongInt {$EndIf};
PHMODULE = ^HMODULE;
PID = {$IfDef Use13} Word {$Else} LongInt {$EndIf};
PPID = ^PID;
TID = {$IfDef Use13} Word {$Else} LongInt {$EndIf};
PTID = ^TID;
HSEM = Pointer; { hsem }
PHSEM = ^HSEM;
{** Common SUP types }
HAB = LHANDLE; { hab }
PHAB = ^HAB;
{** Common GPI/DEV types }
HPS = LHANDLE; { hps }
PHPS = ^HPS;
HDC = LHANDLE;