jwawownt16.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. {******************************************************************************}
  2. { }
  3. { 16 bit Generic Thunks API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: wownt16.h, released June 2000. The original Pascal }
  9. { code is: WowNT16.pas, released December 2000. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. // $Id: JwaWowNT16.pas,v 1.7 2005/09/06 16:36:51 marquardt Exp $
  43. unit JwaWowNT16;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "wownt16.h"'}
  47. {$HPPEMIT ''}
  48. {$I jediapilib.inc}
  49. // (rom) get rid of warnings about "index" directive
  50. {$WARN SYMBOL_PLATFORM OFF}
  51. interface
  52. uses
  53. JwaWindows;
  54. //
  55. // 16:16 -> 0:32 Pointer translation.
  56. //
  57. // GetVDMPointer32W will convert the passed in 16-bit address
  58. // to the equivalent 32-bit flat pointer. The upper 16 bits
  59. // of the address are treated according to the value passed in
  60. // fMode: if fMode = 1, then the hiword of vp is used as a
  61. // protected mode selector. Otherwise it is used as a real mode
  62. // segment value.
  63. // The lower 16 bits are treated as the offset.
  64. //
  65. // The return value is 0 if the selector is invalid.
  66. //
  67. // NOTE: Limit checking is not performed in the retail build
  68. // of Windows NT. It is performed in the checked (debug) build
  69. // of WOW32.DLL, which will cause 0 to be returned when the
  70. // limit is exceeded by the supplied offset.
  71. //
  72. function GetVDMPointer32W(vp: LPVOID; fMode: UINT): DWORD; stdcall;
  73. {$EXTERNALSYM GetVDMPointer32W}
  74. //
  75. // Win32 module management.
  76. //
  77. // The following routines accept parameters that correspond directly
  78. // to the respective Win32 API function calls that they invoke. Refer
  79. // to the Win32 reference documentation for more detail.
  80. function LoadLibraryEx32W(lpszLibFile: LPCSTR; hFile, dwFlags: DWORD): DWORD; stdcall;
  81. {$EXTERNALSYM LoadLibraryEx32W}
  82. function GetProcAddress32W(hModule: DWORD; lpszProc: LPCSTR): DWORD; stdcall;
  83. {$EXTERNALSYM GetProcAddress32W}
  84. function FreeLibrary32W(hLibModule: DWORD): DWORD; stdcall;
  85. {$EXTERNALSYM FreeLibrary32W}
  86. //
  87. // Generic Thunk Routine:
  88. //
  89. // CallProc32W
  90. //
  91. // Transitions to 32 bits and calls specified routine
  92. //
  93. // This routine can pass a variable number of arguments, up to 32, to the
  94. // target 32-bit routine. These arguments are given to CallProc32W following
  95. // the 3 required parameters.
  96. //
  97. // DWORD cParams - Number of optional DWORD parameters (0-32)
  98. //
  99. // LPVOID fAddressConvert - Bit Field, for 16:16 address Convertion. The
  100. // optional parameters can be automatically converted
  101. // from a 16:16 address format to flat by specifying
  102. // a 1 bit in the corresponding position in this mask.
  103. // eg (bit 1 means convert parameter 1 from 16:16
  104. // to flat address before calling routine)
  105. //
  106. // DWORD lpProcAddress - 32 bit native address to call (use LoadLibraryEx32W
  107. // and GetProcAddress32W to get this address).
  108. //
  109. // Returns:
  110. // What ever the API returned on 32 bit side in AX:DX
  111. //
  112. // Error Returns:
  113. // AX = 0, more than 32 parameters.
  114. //
  115. //
  116. // The function prototype must be declared by the application source code
  117. // in the following format:
  118. //
  119. // DWORD FAR PASCAL CallProc32W( DWORD p1, ... , DWORD lpProcAddress,
  120. // DWORD fAddressConvert, DWORD cParams);
  121. //
  122. // where the value in cParams must match the actual number of optional
  123. // parameters (p1-pn) given AND the "DWORD p1, ..." must be replaced by
  124. // the correct number of parameters being passed. For example, passing 3
  125. // parameter would simply require the removal of the ... and it insertion of
  126. // "DWORD p2, DWORD p3" instead. The fAddressConvert parameter uses bit 1
  127. // for the last parameter (p3 in our example), with bit 2 for the next to last,
  128. // etc.
  129. //
  130. // Generic Thunk Routine:
  131. //
  132. // CallProcEx32W
  133. //
  134. // Transitions to 32 bits and calls specified routine
  135. //
  136. // Similar to the CallProc32W function, the CallProcEx32W is an equivalent
  137. // function that is C calling convention and allows easier and more flexible
  138. // prototyping. See the prototype below. The fAddressConvert parameter uses
  139. // bit 1 for the 1st parameter, bit 2 for the 2nd parameter, etc.
  140. //
  141. // Both CallProc32W and CallProcEx32W accept a flag OR'd with the parameter
  142. // count to indicate the calling convention of the function in 32 bits.
  143. // For example, to call a cdecl function in 32-bits with 1 parameter, it would
  144. // look like this:
  145. //
  146. // dwResult = CallProcEx32W( CPEX_DEST_CDECL | 1, 0, dwfn32, p1 );
  147. //
  148. // TODO Variable argument list wrapper!
  149. (*
  150. function CallProcEx32W(nParams, fAddressConvert, lpProcAddress: DWORD): DWORD; cdecl;
  151. {$EXTERNALSYM CallProcEx32W}
  152. *)
  153. const
  154. CPEX_DEST_STDCALL = DWORD($00000000);
  155. {$EXTERNALSYM CPEX_DEST_STDCALL}
  156. CPEX_DEST_CDECL = DWORD($80000000);
  157. {$EXTERNALSYM CPEX_DEST_CDECL}
  158. implementation
  159. uses
  160. JwaWinDLLNames;
  161. //function CallProcEx32W; external wow16lib index 517;
  162. {$IFDEF DYNAMIC_LINK}
  163. var
  164. _GetVDMPointer32W: Pointer;
  165. function GetVDMPointer32W;
  166. begin
  167. GetProcedureAddress(_GetVDMPointer32W, wow16lib, '516');
  168. asm
  169. MOV ESP, EBP
  170. POP EBP
  171. JMP [_GetVDMPointer32W]
  172. end;
  173. end;
  174. var
  175. _LoadLibraryEx32W: Pointer;
  176. function LoadLibraryEx32W;
  177. begin
  178. GetProcedureAddress(_LoadLibraryEx32W, wow16lib, '513');
  179. asm
  180. MOV ESP, EBP
  181. POP EBP
  182. JMP [_LoadLibraryEx32W]
  183. end;
  184. end;
  185. var
  186. _GetProcAddress32W: Pointer;
  187. function GetProcAddress32W;
  188. begin
  189. GetProcedureAddress(_GetProcAddress32W, wow16lib, '515');
  190. asm
  191. MOV ESP, EBP
  192. POP EBP
  193. JMP [_GetProcAddress32W]
  194. end;
  195. end;
  196. var
  197. _FreeLibrary32W: Pointer;
  198. function FreeLibrary32W;
  199. begin
  200. GetProcedureAddress(_FreeLibrary32W, wow16lib, '514');
  201. asm
  202. MOV ESP, EBP
  203. POP EBP
  204. JMP [_FreeLibrary32W]
  205. end;
  206. end;
  207. {$ELSE}
  208. function GetVDMPointer32W; external wow16lib index 516;
  209. function LoadLibraryEx32W; external wow16lib index 513;
  210. function GetProcAddress32W; external wow16lib index 515;
  211. function FreeLibrary32W; external wow16lib index 514;
  212. {$ENDIF DYNAMIC_LINK}
  213. end.