1
{******************************************************************************}
3
{ 32 bit Generic Thunks API interface Unit for Object Pascal }
5
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
6
{ Corporation. All Rights Reserved. }
8
{ The original file is: wownt32.h, released June 2000. The original Pascal }
9
{ code is: WowNT32.pas, released December 2000. The initial developer of the }
10
{ Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
12
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
13
{ Marcel van Brakel. All Rights Reserved. }
15
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
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 }
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 }
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. }
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. }
39
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
41
{******************************************************************************}
43
// $Id: jwawownt32.pas,v 1.1 2005/04/04 07:56:11 marco Exp $
50
{$HPPEMIT '#include "wownt32.h"'}
61
// 16:16 -> 0:32 Pointer translation.
63
// WOWGetVDMPointer will convert the passed in 16-bit address
64
// to the equivalent 32-bit flat pointer. If fProtectedMode
65
// is TRUE, the function treats the upper 16 bits as a selector
66
// in the local descriptor table. If fProtectedMode is FALSE,
67
// the upper 16 bits are treated as a real-mode segment value.
68
// In either case the lower 16 bits are treated as the offset.
70
// The return value is NULL if the selector is invalid.
72
// NOTE: Limit checking is not performed in the retail build
73
// of Windows NT. It is performed in the checked (debug) build
74
// of WOW32.DLL, which will cause NULL to be returned when the
75
// limit is exceeded by the supplied offset.
78
function WOWGetVDMPointer(vp, dwBytes: DWORD; fProtectedMode: BOOL): LPVOID; stdcall;
79
{$EXTERNALSYM WOWGetVDMPointer}
82
// The following two functions are here for compatibility with
83
// Windows 95. On Win95, the global heap can be rearranged,
84
// invalidating flat pointers returned by WOWGetVDMPointer, while
85
// a thunk is executing. On Windows NT, the 16-bit VDM is completely
86
// halted while a thunk executes, so the only way the heap will
87
// be rearranged is if a callback is made to Win16 code.
89
// The Win95 versions of these functions call GlobalFix to
90
// lock down a segment's flat address, and GlobalUnfix to
91
// release the segment.
93
// The Windows NT implementations of these functions do *not*
94
// call GlobalFix/GlobalUnfix on the segment, because there
95
// will not be any heap motion unless a callback occurs.
96
// If your thunk does callback to the 16-bit side, be sure
97
// to discard flat pointers and call WOWGetVDMPointer again
98
// to be sure the flat address is correct.
101
function WOWGetVDMPointerFix(vp, dwBytes: DWORD; fProtectedMode: BOOL): LPVOID; stdcall;
102
{$EXTERNALSYM WOWGetVDMPointerFix}
103
procedure WOWGetVDMPointerUnfix(vp: DWORD); stdcall;
104
{$EXTERNALSYM WOWGetVDMPointerUnfix}
107
// Win16 memory management.
109
// These functions can be used to manage memory in the Win16
110
// heap. The following four functions are identical to their
111
// Win16 counterparts, except that they are called from Win32
115
function WOWGlobalAlloc16(wFlags: WORD; cb: DWORD): WORD; stdcall;
116
{$EXTERNALSYM WOWGlobalAlloc16}
117
function WOWGlobalFree16(hMem: WORD): WORD; stdcall;
118
{$EXTERNALSYM WOWGlobalFree16}
119
function WOWGlobalLock16(hMem: WORD): DWORD; stdcall;
120
{$EXTERNALSYM WOWGlobalLock16}
121
function WOWGlobalUnlock16(hMem: WORD): BOOL; stdcall;
122
{$EXTERNALSYM WOWGlobalUnlock16}
125
// The following three functions combine two common operations in
126
// one switch to 16-bit mode.
129
function WOWGlobalAllocLock16(wFlags: WORD; cb: DWORD; var phMem: WORD): DWORD; stdcall;
130
{$EXTERNALSYM WOWGlobalAllocLock16}
131
function WOWGlobalUnlockFree16(vpMem: DWORD): WORD; stdcall;
132
{$EXTERNALSYM WOWGlobalUnlockFree16}
133
function WOWGlobalLockSize16(hMem: WORD; pcb: PDWORD): DWORD; stdcall;
134
{$EXTERNALSYM WOWGlobalLockSize16}
137
// Yielding the Win16 nonpreemptive scheduler
139
// The following two functions are provided for Win32 code called
140
// via Generic Thunks which needs to yield the Win16 scheduler so
141
// that tasks in that VDM can execute while the thunk waits for
142
// something to complete. These two functions are functionally
143
// identical to calling back to 16-bit code which calls Yield or
147
procedure WOWYield16; stdcall;
148
{$EXTERNALSYM WOWYield16}
149
procedure WOWDirectedYield16(htask16: WORD); stdcall;
150
{$EXTERNALSYM WOWDirectedYield16}
153
// 16 <--> 32 Handle mapping functions.
155
// NOTE: While some of these functions perform trivial
156
// conversions, these functions must be used to maintain
157
// compatibility with future versions of Windows NT which
158
// may require different handle mapping.
178
{$EXTERNALSYM _WOW_HANDLE_TYPE}
179
WOW_HANDLE_TYPE = _WOW_HANDLE_TYPE;
180
{$EXTERNALSYM WOW_HANDLE_TYPE}
181
TWowHandleType = WOW_HANDLE_TYPE;
183
function WOWHandle32(Handle: WORD; Type_: WOW_HANDLE_TYPE): HANDLE; stdcall;
184
{$EXTERNALSYM WOWHandle32}
185
function WOWHandle16(Handle: HANDLE; Type_: WOW_HANDLE_TYPE): WORD; stdcall;
186
{$EXTERNALSYM WOWHandle16}
188
function HWND_32(h16: WORD): HANDLE;
189
{$EXTERNALSYM HWND_32}
190
function HMENU_32(h16: WORD): HANDLE;
191
{$EXTERNALSYM HMENU_32}
192
function HDWP_32(h16: WORD): HANDLE;
193
{$EXTERNALSYM HDWP_32}
194
function HDROP_32(h16: WORD): HANDLE;
195
{$EXTERNALSYM HDROP_32}
196
function HDC_32(h16: WORD): HANDLE;
197
{$EXTERNALSYM HDC_32}
198
function HFONT_32(h16: WORD): HANDLE;
199
{$EXTERNALSYM HFONT_32}
200
function HMETAFILE_32(h16: WORD): HANDLE;
201
{$EXTERNALSYM HMETAFILE_32}
202
function HRGN_32(h16: WORD): HANDLE;
203
{$EXTERNALSYM HRGN_32}
204
function HBITMAP_32(h16: WORD): HANDLE;
205
{$EXTERNALSYM HBITMAP_32}
206
function HBRUSH_32(h16: WORD): HANDLE;
207
{$EXTERNALSYM HBRUSH_32}
208
function HPALETTE_32(h16: WORD): HANDLE;
209
{$EXTERNALSYM HPALETTE_32}
210
function HPEN_32(h16: WORD): HANDLE;
211
{$EXTERNALSYM HPEN_32}
212
function HACCEL_32(h16: WORD): HANDLE;
213
{$EXTERNALSYM HACCEL_32}
214
function HTASK_32(h16: WORD): HANDLE;
215
{$EXTERNALSYM HTASK_32}
216
function FULLHWND_32(h16: WORD): HANDLE;
217
{$EXTERNALSYM FULLHWND_32}
218
function HWND_16(h32: HANDLE): WORD;
219
{$EXTERNALSYM HWND_16}
220
function HMENU_16(h32: HANDLE): WORD;
221
{$EXTERNALSYM HMENU_16}
222
function HDWP_16(h32: HANDLE): WORD;
223
{$EXTERNALSYM HDWP_16}
224
function HDROP_16(h32: HANDLE): WORD;
225
{$EXTERNALSYM HDROP_16}
226
function HDC_16(h32: HANDLE): WORD;
227
{$EXTERNALSYM HDC_16}
228
function HFONT_16(h32: HANDLE): WORD;
229
{$EXTERNALSYM HFONT_16}
230
function HMETAFILE_16(h32: HANDLE): WORD;
231
{$EXTERNALSYM HMETAFILE_16}
232
function HRGN_16(h32: HANDLE): WORD;
233
{$EXTERNALSYM HRGN_16}
234
function HBITMAP_16(h32: HANDLE): WORD;
235
{$EXTERNALSYM HBITMAP_16}
236
function HBRUSH_16(h32: HANDLE): WORD;
237
{$EXTERNALSYM HBRUSH_16}
238
function HPALETTE_16(h32: HANDLE): WORD;
239
{$EXTERNALSYM HPALETTE_16}
240
function HPEN_16(h32: HANDLE): WORD;
241
{$EXTERNALSYM HPEN_16}
242
function HACCEL_16(h32: HANDLE): WORD;
243
{$EXTERNALSYM HACCEL_16}
244
function HTASK_16(h32: HANDLE): WORD;
245
{$EXTERNALSYM HTASK_16}
248
// Generic Callbacks.
250
// WOWCallback16 can be used in Win32 code called
251
// from 16-bit (such as by using Generic Thunks) to call back to
252
// the 16-bit side. The function called must be declared similarly
255
// LONG FAR PASCAL CallbackRoutine(DWORD dwParam);
257
// If you are passing a pointer, declare the parameter as such:
259
// LONG FAR PASCAL CallbackRoutine(VOID FAR *vp);
261
// NOTE: If you are passing a pointer, you'll need to get the
262
// pointer using WOWGlobalAlloc16 or WOWGlobalAllocLock16
264
// If the function called returns a WORD instead of a DWORD, the
265
// upper 16 bits of the return value is undefined. Similarly, if
266
// the function called has no return value, the entire return value
269
// WOWCallback16Ex allows any combination of arguments up to
270
// WCB16_MAX_CBARGS bytes total to be passed to the 16-bit routine.
271
// cbArgs is used to properly clean up the 16-bit stack after calling
272
// the routine. Regardless of the value of cbArgs, WCB16_MAX_CBARGS
273
// bytes will always be copied from pArgs to the 16-bit stack. If
274
// pArgs is less than WCB16_MAX_CBARGS bytes from the end of a page,
275
// and the next page is inaccessible, WOWCallback16Ex will incur an
278
// If cbArgs is larger than the WCB16_MAX_ARGS which the running
279
// system supports, the function returns FALSE and GetLastError
280
// returns ERROR_INVALID_PARAMETER. Otherwise the function
281
// returns TRUE and the DWORD pointed to by pdwRetCode contains
282
// the return code from the callback routine. If the callback
283
// routine returns a WORD, the HIWORD of the return code is
284
// undefined and should be ignored using LOWORD(dwRetCode).
286
// WOWCallback16Ex can call routines using the PASCAL and CDECL
287
// calling conventions. The default is to use the PASCAL
288
// calling convention. To use CDECL, pass WCB16_CDECL in the
289
// dwFlags parameter.
291
// The arguments pointed to by pArgs must be in the correct
292
// order for the callback routine's calling convention.
293
// To call the PASCAL routine SetWindowText,
295
// LONG FAR PASCAL SetWindowText(HWND hwnd, LPCSTR lpsz);
297
// pArgs would point to an array of words:
299
// WORD SetWindowTextArgs[] = {OFFSETOF(lpsz), SELECTOROF(lpsz), hwnd};
301
// In other words, the arguments are placed in the array in reverse
302
// order with the least significant word first for DWORDs and offset
303
// first for FAR pointers.
305
// To call the CDECL routine wsprintf, for example
307
// LPSTR lpszFormat = "%d %s";
308
// int _cdecl wsprintf(lpsz, lpszFormat, nValue. lpszString);
310
// pArgs would point to the array:
312
// WORD wsprintfArgs[] = {OFFSETOF(lpsz), SELECTOROF(lpsz),
313
// OFFSETOF(lpszFormat), SELECTOROF(lpszFormat),
315
// OFFSETOF(lpszString), SELECTOROF(lpszString)};
317
// In other words, the arguments are placed in the array in the order
318
// listed in the function prototype with the least significant word
319
// first for DWORDs and offset first for FAR pointers.
322
function WOWCallback16(vpfn16: DWORD; dwParam: DWORD): DWORD; stdcall;
323
{$EXTERNALSYM WOWCallback16}
326
WCB16_MAX_CBARGS = 16;
327
{$EXTERNALSYM WCB16_MAX_CBARGS}
330
{$EXTERNALSYM WCB16_PASCAL}
332
{$EXTERNALSYM WCB16_CDECL}
334
function WOWCallback16Ex(vpfn16, dwFlags, cbArgs: DWORD; pArgs: PVOID; pdwRetCode: PDWORD): BOOL; stdcall;
335
{$EXTERNALSYM WOWCallback16Ex}
340
wow32lib = 'wow32.dll';
342
function HWND_32(h16: WORD): HANDLE;
344
Result := WOWHandle32(h16, WOW_TYPE_HWND);
347
function HMENU_32(h16: WORD): HANDLE;
349
Result := WOWHandle32(h16, WOW_TYPE_HMENU);
352
function HDWP_32(h16: WORD): HANDLE;
354
Result := WOWHandle32(h16, WOW_TYPE_HDWP);
357
function HDROP_32(h16: WORD): HANDLE;
359
Result := WOWHandle32(h16, WOW_TYPE_HDROP);
362
function HDC_32(h16: WORD): HANDLE;
364
Result := WOWHandle32(h16, WOW_TYPE_HDC);
367
function HFONT_32(h16: WORD): HANDLE;
369
Result := WOWHandle32(h16, WOW_TYPE_HFONT);
372
function HMETAFILE_32(h16: WORD): HANDLE;
374
Result := WOWHandle32(h16, WOW_TYPE_HMETAFILE);
377
function HRGN_32(h16: WORD): HANDLE;
379
Result := WOWHandle32(h16, WOW_TYPE_HRGN);
382
function HBITMAP_32(h16: WORD): HANDLE;
384
Result := WOWHandle32(h16, WOW_TYPE_HBITMAP);
387
function HBRUSH_32(h16: WORD): HANDLE;
389
Result := WOWHandle32(h16, WOW_TYPE_HBRUSH);
392
function HPALETTE_32(h16: WORD): HANDLE;
394
Result := WOWHandle32(h16, WOW_TYPE_HPALETTE);
397
function HPEN_32(h16: WORD): HANDLE;
399
Result := WOWHandle32(h16, WOW_TYPE_HPEN);
402
function HACCEL_32(h16: WORD): HANDLE;
404
Result := WOWHandle32(h16, WOW_TYPE_HACCEL);
407
function HTASK_32(h16: WORD): HANDLE;
409
Result := WOWHandle32(h16, WOW_TYPE_HTASK);
412
function FULLHWND_32(h16: WORD): HANDLE;
414
Result := WOWHandle32(h16, WOW_TYPE_FULLHWND);
417
function HWND_16(h32: HANDLE): WORD;
419
Result := WOWHandle16(h32, WOW_TYPE_HWND);
422
function HMENU_16(h32: HANDLE): WORD;
424
Result := WOWHandle16(h32, WOW_TYPE_HMENU);
427
function HDWP_16(h32: HANDLE): WORD;
429
Result := WOWHandle16(h32, WOW_TYPE_HDWP);
432
function HDROP_16(h32: HANDLE): WORD;
434
Result := WOWHandle16(h32, WOW_TYPE_HDROP);
437
function HDC_16(h32: HANDLE): WORD;
439
Result := WOWHandle16(h32, WOW_TYPE_HDC);
442
function HFONT_16(h32: HANDLE): WORD;
444
Result := WOWHandle16(h32, WOW_TYPE_HFONT);
447
function HMETAFILE_16(h32: HANDLE): WORD;
449
Result := WOWHandle16(h32, WOW_TYPE_HMETAFILE);
452
function HRGN_16(h32: HANDLE): WORD;
454
Result := WOWHandle16(h32, WOW_TYPE_HRGN);
457
function HBITMAP_16(h32: HANDLE): WORD;
459
Result := WOWHandle16(h32, WOW_TYPE_HBITMAP);
462
function HBRUSH_16(h32: HANDLE): WORD;
464
Result := WOWHandle16(h32, WOW_TYPE_HBRUSH);
467
function HPALETTE_16(h32: HANDLE): WORD;
469
Result := WOWHandle16(h32, WOW_TYPE_HPALETTE);
472
function HPEN_16(h32: HANDLE): WORD;
474
Result := WOWHandle16(h32, WOW_TYPE_HPEN);
477
function HACCEL_16(h32: HANDLE): WORD;
479
Result := WOWHandle16(h32, WOW_TYPE_HACCEL);
482
function HTASK_16(h32: HANDLE): WORD;
484
Result := WOWHandle16(h32, WOW_TYPE_HTASK);
487
{$IFDEF DYNAMIC_LINK}
490
_WOWGetVDMPointer: Pointer;
492
function WOWGetVDMPointer;
494
GetProcedureAddress(_WOWGetVDMPointer, wow32lib, 'WOWGetVDMPointer');
498
JMP [_WOWGetVDMPointer]
503
_WOWGetVDMPointerFix: Pointer;
505
function WOWGetVDMPointerFix;
507
GetProcedureAddress(_WOWGetVDMPointerFix, wow32lib, 'WOWGetVDMPointerFix');
511
JMP [_WOWGetVDMPointerFix]
516
_WOWGetVDMPointerUnfix: Pointer;
518
procedure WOWGetVDMPointerUnfix;
520
GetProcedureAddress(_WOWGetVDMPointerUnfix, wow32lib, 'WOWGetVDMPointerUnfix');
524
JMP [_WOWGetVDMPointerUnfix]
529
_WOWGlobalAlloc16: Pointer;
531
function WOWGlobalAlloc16;
533
GetProcedureAddress(_WOWGlobalAlloc16, wow32lib, 'WOWGlobalAlloc16');
537
JMP [_WOWGlobalAlloc16]
542
_WOWGlobalFree16: Pointer;
544
function WOWGlobalFree16;
546
GetProcedureAddress(_WOWGlobalFree16, wow32lib, 'WOWGlobalFree16');
550
JMP [_WOWGlobalFree16]
555
_WOWGlobalLock16: Pointer;
557
function WOWGlobalLock16;
559
GetProcedureAddress(_WOWGlobalLock16, wow32lib, 'WOWGlobalLock16');
563
JMP [_WOWGlobalLock16]
568
_WOWGlobalUnlock16: Pointer;
570
function WOWGlobalUnlock16;
572
GetProcedureAddress(_WOWGlobalUnlock16, wow32lib, 'WOWGlobalUnlock16');
576
JMP [_WOWGlobalUnlock16]
581
_WOWGlobalAllocLock16: Pointer;
583
function WOWGlobalAllocLock16;
585
GetProcedureAddress(_WOWGlobalAllocLock16, wow32lib, 'WOWGlobalAllocLock16');
589
JMP [_WOWGlobalAllocLock16]
594
_WOWGlobalUnlockFree16: Pointer;
596
function WOWGlobalUnlockFree16;
598
GetProcedureAddress(_WOWGlobalUnlockFree16, wow32lib, 'WOWGlobalUnlockFree16');
602
JMP [_WOWGlobalUnlockFree16]
607
_WOWGlobalLockSize16: Pointer;
609
function WOWGlobalLockSize16;
611
GetProcedureAddress(_WOWGlobalLockSize16, wow32lib, 'WOWGlobalLockSize16');
615
JMP [_WOWGlobalLockSize16]
620
_WOWYield16: Pointer;
622
procedure WOWYield16;
624
GetProcedureAddress(_WOWYield16, wow32lib, 'WOWYield16');
633
_WOWDirectedYield16: Pointer;
635
procedure WOWDirectedYield16;
637
GetProcedureAddress(_WOWDirectedYield16, wow32lib, 'WOWDirectedYield16');
641
JMP [_WOWDirectedYield16]
646
_WOWHandle32: Pointer;
648
function WOWHandle32;
650
GetProcedureAddress(_WOWHandle32, wow32lib, 'WOWHandle32');
659
_WOWHandle16: Pointer;
661
function WOWHandle16;
663
GetProcedureAddress(_WOWHandle16, wow32lib, 'WOWHandle16');
672
_WOWCallback16: Pointer;
674
function WOWCallback16;
676
GetProcedureAddress(_WOWCallback16, wow32lib, 'WOWCallback16');
685
_WOWCallback16Ex: Pointer;
687
function WOWCallback16Ex;
689
GetProcedureAddress(_WOWCallback16Ex, wow32lib, 'WOWCallback16Ex');
693
JMP [_WOWCallback16Ex]
699
function WOWGetVDMPointer; external wow32lib name 'WOWGetVDMPointer';
700
function WOWGetVDMPointerFix; external wow32lib name 'WOWGetVDMPointerFix';
701
procedure WOWGetVDMPointerUnfix; external wow32lib name 'WOWGetVDMPointerUnfix';
702
function WOWGlobalAlloc16; external wow32lib name 'WOWGlobalAlloc16';
703
function WOWGlobalFree16; external wow32lib name 'WOWGlobalFree16';
704
function WOWGlobalLock16; external wow32lib name 'WOWGlobalLock16';
705
function WOWGlobalUnlock16; external wow32lib name 'WOWGlobalUnlock16';
706
function WOWGlobalAllocLock16; external wow32lib name 'WOWGlobalAllocLock16';
707
function WOWGlobalUnlockFree16; external wow32lib name 'WOWGlobalUnlockFree16';
708
function WOWGlobalLockSize16; external wow32lib name 'WOWGlobalLockSize16';
709
procedure WOWYield16; external wow32lib name 'WOWYield16';
710
procedure WOWDirectedYield16; external wow32lib name 'WOWDirectedYield16';
711
function WOWHandle32; external wow32lib name 'WOWHandle32';
712
function WOWHandle16; external wow32lib name 'WOWHandle16';
713
function WOWCallback16; external wow32lib name 'WOWCallback16';
714
function WOWCallback16Ex; external wow32lib name 'WOWCallback16Ex';
716
{$ENDIF DYNAMIC_LINK}