home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 13.ddi / RTLWIN.ZIP / WINAPI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-28  |  10.5 KB  |  306 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal Runtime Library                    }
  5. {       DOS Protected-mode Interface Unit               }
  6. {                                                       }
  7. {       Copyright (c) 1991,92 Borland International     }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit WinAPI;
  12.  
  13. {$S-}
  14.  
  15. interface
  16.  
  17. { Generic types }
  18.  
  19. type
  20.   Bool     = WordBool;          { Windows compatible boolean }
  21.   THandle  = Word;              { Global memory handle }
  22.   TFarProc = Pointer;           { Procedure address }
  23.  
  24. { Flags returned by GetWinFlags }
  25.  
  26. const
  27.   wf_PMode      = $00000001;    { Running in protected mode }
  28.   wf_CPU286     = $00000002;    { System CPU is an 80286 }
  29.   wf_CPU386     = $00000004;    { System CPU is an 80386 }
  30.   wf_CPU486     = $00000008;    { System CPU is an 80486 }
  31.   wf_Standard   = $00000010;    { Running in standard mode }
  32.   wf_Enhanced   = $00000020;    { Running in enhanced mode }
  33.   wf_CPU086     = $00000040;    { System CPU is an 8086 }
  34.   wf_CPU186     = $00000080;    { System CPU is an 80186 }
  35.   wf_LargeFrame = $00000100;    { Windows EMS large-frame configuration }
  36.   wf_SmallFrame = $00000200;    { Windows EMS small-frame configuration }
  37.   wf_80x87      = $00000400;    { System contains a math coprocessor }
  38.   wf_DPMI       = $80000000;    { Running in DOS protected mode }
  39.  
  40. { GlobalAlloc and GlobalReAlloc flags }
  41.  
  42. const
  43.   gmem_Fixed       = $0000;     { Allocate fixed memory }
  44.   gmem_Moveable    = $0002;     { Allocate moveable memory }
  45.   gmem_NoCompact   = $0010;     { Don't compact when allocating }
  46.   gmem_NoDiscard   = $0020;     { Don't discard when allocating }
  47.   gmem_ZeroInit    = $0040;     { Initialize memory contents to zero }
  48.   gmem_Modify      = $0080;     { Modify memory flags }
  49.   gmem_Discardable = $0100;     { Allocate discardable memory }
  50.   gmem_Not_Banked  = $1000;     { Allocate non-banked memory }
  51.   gmem_DDEShare    = $2000;     { Allocate sharable memory }
  52.   gmem_Notify      = $4000;     { Notify upon discarding }
  53.  
  54. { Flags returned by GlobalFlags (in addition to gmem_Discardable) }
  55.  
  56. const
  57.   gmem_Discarded = $4000;
  58.   gmem_LockCount = $00FF;
  59.  
  60. { MessageBox Flags }
  61.  
  62. const
  63.   mb_Ok               = $0000;
  64.   mb_OkCancel         = $0001;
  65.   mb_AbortRetryIgnore = $0002;
  66.   mb_YesNoCancel      = $0003;
  67.   mb_YesNo            = $0004;
  68.   mb_RetryCancel      = $0005;
  69.  
  70.   mb_IconHand         = $0010;
  71.   mb_IconStop         = $0010;
  72.   mb_IconQuestion     = $0020;
  73.   mb_IconExclamation  = $0030;
  74.   mb_IconAsterisk     = $0040;
  75.   mb_IconInformation  = $0040;
  76.  
  77.   mb_DefButton1       = $0000;
  78.   mb_DefButton2       = $0100;
  79.   mb_DefButton3       = $0200;
  80.  
  81.   mb_ApplModal        = $0000;
  82.   mb_SystemModal      = $1000;
  83.   mb_TaskModal        = $2000;
  84.  
  85.   mb_NoFocus          = $8000;
  86.  
  87.   mb_TypeMask         = $000F;
  88.   mb_IconMask         = $00F0;
  89.   mb_DefMask          = $0F00;
  90.   mb_ModeMask         = $3000;
  91.   mb_MiscMask         = $C000;
  92.  
  93. { MessageBox return values }
  94.  
  95. const
  96.   id_Ok     = 1;
  97.   id_Cancel = 2;
  98.   id_Abort  = 3;
  99.   id_Retry  = 4;
  100.   id_Ignore = 5;
  101.   id_Yes    = 6;
  102.   id_No     = 7;
  103.  
  104. { Windows API routines }
  105.  
  106. function AccessResource(Instance, ResInfo: THandle): Integer;
  107. function AllocDStoCSAlias(Selector: Word): Word;
  108. function AllocSelector(Selector: Word): Word;
  109. function ChangeSelector(SourceSelector, DestSelector: Word): Word;
  110. procedure DOS3Call;
  111. procedure FatalExit(Code: Integer);
  112. function FindResource(Instance: THandle; Name, ResType: PChar): THandle;
  113. procedure FreeLibrary(LibModule: THandle);
  114. function FreeResource(ResData: THandle): Bool;
  115. function FreeSelector(Selector: Word): Word;
  116. function GetDOSEnvironment: PChar;
  117. function GetFreeSpace(Flag: Word): Longint;
  118. function GetModuleFileName(Module: THandle; Filename: PChar; Size: Integer): Integer;
  119. function GetModuleHandle(ModuleName: PChar): THandle;
  120. function GetModuleUsage(Module: THandle): Integer;
  121. function GetProcAddress(Module: THandle; ProcName: PChar): TFarProc;
  122. function GetSelectorBase(Selector: Word): Longint;
  123. function GetSelectorLimit(Selector: Word): Longint;
  124. function GetVersion: Longint;
  125. function GetWinFlags: Longint;
  126. function GlobalAlloc(Flags: Word; Bytes: Longint): THandle;
  127. function GlobalAllocPtr(Flags: Word; Bytes: Longint): Pointer; 
  128. function GlobalCompact(MinFree: Longint): Longint;
  129. function GlobalDiscard(Mem: THandle): THandle;
  130. function GlobalDosAlloc(Bytes: Longint): Longint;
  131. function GlobalDosFree(Selector: Word): Word;
  132. procedure GlobalFix(Mem: THandle);
  133. function GlobalFlags(Mem: THandle): Word;
  134. function GlobalFree(Mem: THandle): THandle;
  135. function GlobalFreePtr(P: Pointer): THandle;
  136. function GlobalHandle(Mem: Word): Longint;
  137. function GlobalLock(Mem: THandle): Pointer;
  138. function GlobalLRUNewest(Mem: THandle): THandle;
  139. function GlobalLRUOldest(Mem: THandle): THandle;
  140. procedure GlobalNotify(NotifyProc: TFarProc);
  141. function GlobalPageLock(Selector: THandle): Word;
  142. function GlobalPageUnlock(Selector: THandle): Word;
  143. function GlobalPtrHandle(P: Pointer): THandle; 
  144. function GlobalReAlloc(Mem: THandle; Bytes: Longint; Flags: Word): THandle;
  145. function GlobalReAllocPtr(P: Pointer; Bytes: Longint; Flags: Word): Pointer;
  146. function GlobalSize(Mem: THandle): Longint;
  147. function GlobalUnfix(Mem: THandle): Bool;
  148. function GlobalUnlock(Mem: THandle): Bool;
  149. function LoadLibrary(LibFileName: PChar): THandle;
  150. function LoadResource(Instance: THandle; ResInfo: THandle): THandle;
  151. function LoadString(Instance: THandle; ID: Word; Buffer: PChar;
  152.   BufferMax: Integer): Integer;
  153. function LockResource(ResData: THandle): Pointer;
  154. function LockSegment(Segment: Word): THandle;
  155. function MessageBox(WndParent: THandle; Text, Caption: PChar;
  156.   TextType: Word): Integer;
  157. function PrestoChangoSelector(SourceSelector, DestSelector: Word): Word;
  158. function SetSelectorBase(Selector: Word; Base: Longint): Word;
  159. function SetSelectorLimit(Selector: Word; Limit: Longint): Word;
  160. function SizeOfResource(Instance, ResInfo: THandle): Longint;
  161. function UnlockResource(ResData: THandle): Bool;
  162. function UnlockSegment(Segment: Word): THandle;
  163.  
  164. { Inline routines }
  165.  
  166. function MakeLong(A, B: Word): Longint;
  167. inline(
  168.   $5A/    { POP DX }
  169.   $58);   { POP AX }
  170.  
  171. function LoWord(A: Longint): Word;
  172. inline(
  173.   $58/    { POP AX }
  174.   $5A);   { POP DX }
  175.  
  176. function HiWord(A: Longint): Word;
  177. inline(
  178.   $5A/    { POP DX }
  179.   $58);   { POP AX }
  180.  
  181. function LoByte(A: Word): Byte;
  182. inline(
  183.   $58/       { POP AX    }
  184.   $32/$E4);  { XOR AH,AH }
  185.  
  186. function HiByte(A: Word): Byte;
  187. inline(
  188.   $58/       { POP AX    }
  189.   $8A/$C4/   { MOV AL,AH }
  190.   $32/$E4);  { XOR AH,AH }
  191.  
  192. implementation
  193.  
  194. { KERNEL routines }
  195.  
  196. procedure FatalExit;            external 'KERNEL' index 1;
  197. function GetVersion;            external 'KERNEL' index 3;
  198. function GlobalAlloc;            external 'KERNEL' index 15;
  199. function GlobalReAlloc;            external 'KERNEL' index 16;
  200. function GlobalFree;            external 'KERNEL' index 17;
  201. function GlobalLock;            external 'KERNEL' index 18;
  202. function GlobalUnlock;            external 'KERNEL' index 19;
  203. function UnlockResource;        external 'KERNEL' index 19;
  204. function GlobalSize;            external 'KERNEL' index 20;
  205. function GlobalHandle;            external 'KERNEL' index 21;
  206. function GlobalFlags;            external 'KERNEL' index 22;
  207. function LockSegment;            external 'KERNEL' index 23;
  208. function UnlockSegment;            external 'KERNEL' index 24;
  209. function GlobalCompact;            external 'KERNEL' index 25;
  210. function GetModuleHandle;        external 'KERNEL' index 47;
  211. function GetModuleUsage;        external 'KERNEL' index 48;
  212. function GetModuleFileName;        external 'KERNEL' index 49;
  213. function GetProcAddress;        external 'KERNEL' index 50;
  214. function FindResource;            external 'KERNEL' index 60;
  215. function LoadResource;            external 'KERNEL' index 61;
  216. function LockResource;            external 'KERNEL' index 62;
  217. function FreeResource;            external 'KERNEL' index 63;
  218. function AccessResource;        external 'KERNEL' index 64;
  219. function SizeOfResource;        external 'KERNEL' index 65;
  220. function LoadLibrary;            external 'KERNEL' index 95;
  221. procedure FreeLibrary;            external 'KERNEL' index 96;
  222. procedure DOS3Call;            external 'KERNEL' index 102;
  223. function GetDOSEnvironment;             external 'KERNEL' index 131;
  224. function GetWinFlags;            external 'KERNEL' index 132;
  225. procedure GlobalNotify;            external 'KERNEL' index 154;
  226. function GlobalLRUOldest;        external 'KERNEL' index 163;
  227. function GlobalLRUNewest;        external 'KERNEL' index 164;
  228. function GetFreeSpace;            external 'KERNEL' index 169;
  229. function AllocDStoCSAlias;              external 'KERNEL' index 171;
  230. function AllocSelector;                 external 'KERNEL' index 175;
  231. function FreeSelector;                  external 'KERNEL' index 176;
  232. function ChangeSelector;        external 'KERNEL' index 177;
  233. function PrestoChangoSelector;        external 'KERNEL' index 177;
  234. function GlobalDosAlloc;        external 'KERNEL' index 184;
  235. function GlobalDosFree;            external 'KERNEL' index 185;
  236. function GetSelectorBase;        external 'KERNEL' index 186;
  237. function SetSelectorBase;        external 'KERNEL' index 187;
  238. function GetSelectorLimit;        external 'KERNEL' index 188;
  239. function SetSelectorLimit;        external 'KERNEL' index 189;
  240. function GlobalPageLock;                external 'KERNEL' index 191;
  241. function GlobalPageUnlock;              external 'KERNEL' index 192;
  242. procedure GlobalFix;                    external 'KERNEL' index 197;
  243. function GlobalUnfix;                   external 'KERNEL' index 198;
  244.  
  245. { USER routines }
  246.  
  247. function MessageBox;            external 'USER' index 1;
  248. function LoadString;            external 'USER' index 176;
  249.  
  250. { Wrapper routines }
  251.  
  252. function GlobalDiscard(Mem: THandle): THandle; assembler;
  253. asm
  254.     PUSH    Mem
  255.     XOR    AX,AX
  256.     PUSH    AX
  257.     PUSH    AX
  258.     MOV    AX,gmem_Moveable
  259.     PUSH    AX
  260.     CALL    GlobalReAlloc
  261. end;
  262.  
  263. function GlobalPtrHandle(P: Pointer): THandle; assembler;
  264. asm
  265.     PUSH    P.Word[2]
  266.     CALL    GlobalHandle
  267. end;
  268.  
  269. function GlobalAllocPtr(Flags: Word; Bytes: Longint): Pointer; assembler;
  270. asm
  271.     PUSH    Flags
  272.     PUSH    Bytes.Word[2]
  273.     PUSH    Bytes.Word[0]
  274.     CALL    GlobalAlloc
  275.     PUSH    AX
  276.     CALL    GlobalLock
  277. end;
  278.  
  279. function GlobalReAllocPtr(P: Pointer; Bytes: Longint;
  280.   Flags: Word): Pointer; assembler;
  281. asm
  282.     PUSH    P.Word[2]
  283.     CALL    GlobalHandle
  284.     PUSH    AX
  285.     PUSH    AX
  286.     CALL    GlobalUnlock
  287.     PUSH    Bytes.Word[2]
  288.     PUSH    Bytes.Word[0]
  289.     PUSH    Flags
  290.     CALL    GlobalReAlloc
  291.     PUSH    AX
  292.     CALL    GlobalLock
  293. end;
  294.  
  295. function GlobalFreePtr(P: Pointer): THandle; assembler;
  296. asm
  297.     PUSH    P.Word[2]
  298.     CALL    GlobalHandle
  299.     PUSH    AX
  300.     PUSH    AX
  301.     CALL    GlobalUnlock
  302.     CALL    GlobalFree
  303. end;
  304.  
  305. end.
  306.