Source file: /~heha/messtech/ddegpib.zip/SRC/THUNK16.PAS

unit thunk16;
{Generic Thunk - calling 32bit DLLs from 16bit code. Works with Win9x and NT,
 but not Win32s. Converted to Borland Pascal h#s 10/99}
{--- cut here ---}
{ example taken from MSDN CD16 KB&BL/Win32SDK KBase/
  Programming Related Articles/Types of thunking available
type
 TOSVersionInfo=record
  dwOSVersionInfoSize, dwMajorVersion, dwMinorVersion, dwBuildNumber,
    dwPlatformID: LongInt;
  szCSDVersion: array[0..127] of Char;
 end;
procedure MyGetVersionEx(var lpVersionInfo: TOSVersionInfo);
 var
  hKernel32, lpGetVersionEx: LongInt;
 begin
  hKernel32:=LoadLibraryEx32W('KERNEL32.DLL',0,0);
  lpGetVersionEx:=GetProcAddress32W(hKernel32,'GetVersionExA');
  lpVersionInfo.dwOSVersionInfoSize:=sizeof(TOSVersionInfo);
  CallProc32W1(LongInt(@lpVersionInfo),lpGetVersionEx,1,1);
(* The last 1 says: One parameter (lpVersionInfo).
 * The first 1 is a bitmap, whether the parameter is an Integer(0)
 *   or a Pointer(1).
 *   Here, it's a pointer, let generic thunk convert it, therefore 1
 *)
  FreeLibrary32W(hKernel32);
 end;}
{--- cut here ---}
 
{$C MOVEABLE PRELOAD PERMANENT}	{gleiche Attribute wie Unit SYSTEM}
{$F-,A+,G+,K+,W-}
{$I-,Q-,R-,S-}
{$V+,B-,X+,T+,P+}
interface
uses WinTypes;
function LoadLibraryEx32W(lpszLibFile: PChar; reservedhFile, dwFlags: LongInt): LongInt;
function FreeLibrary32W(hInst: LongInt): Bool;
function GetProcAddress32W(hInst: LongInt; lpszProc: PChar): LongInt;
function GetVDMPointer32W(lpAddress: Pointer; fProtectedMode: Bool): LongInt;
function CallProc32W0(lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProc32W1(p1, lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProc32W2(p1,p2, lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProc32W3(p1,p2,p3, lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProc32W4(p1,p2,p3,p4, lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProc32W5(p1,p2,p3,p4,p5, lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProc32W6(p1,p2,p3,p4,p5,p6, lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProc32W7(p1,p2,p3,p4,p5,p6,p7, lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProc32W8(p1,p2,p3,p4,p5,p6,p7,p8, lpProcAddress32, fAddressConvert, nParams: LongInt): LongInt;
function CallProcEx32W: LongInt;	{cdecl, for use in assembly routines; reverse parameter order}
const	{dwFlags in LoadLibraryEx32W}
 Dont_Resolve_DLL_References=1;
 Load_Library_As_Datafile=2;
 Load_With_Altered_Search_Path=8;
const	{nParams OR-able flag for calling convention}
 CPEX_Dest_stdcall	=0;
 CPEX_Dest_cdecl	=$80000000;
const	{Root keys for registry access}
 HKey_Current_User	=$80000001;
 HKey_Local_Machine	=$80000002;
 HKey_Users		=$80000003;
 HKey_Performance_Data	=$80000004;	{WinNT only}
 HKey_Current_Config	=$80000005;
 HKey_Dyn_Data		=$80000006;	{Win9x only}

 REG_None			=0;
 REG_SZ				=1;
 REG_Expand_SZ			=2;
 REG_Binary			=3;
 REG_DWord			=4;
 REG_DWord_Little_Endian	=4;
 REG_DWord_Big_Endian		=5;
 REG_Link			=6;
 REG_Multi_SZ			=7;
 REG_Resource_List		=8;
 REG_Full_Resource_Descriptor	=9;
 REG_Resource_Requirements_List	=10;

 SERVICE_No_Change		=-1;

 SERVICE_Kernel_Driver		=$1;
 SERVICE_File_System_Driver	=$2;
 SERVICE_Adapter		=$4;
 SERVICE_Recognizer_Driver	=$8;
 SERVICE_Driver			=$B;

 SERVICE_Boot_Start		=0;
 SERVICE_System_Start		=1;
 SERVICE_Auto_Start		=2;
 SERVICE_Demand_Start		=3;
 SERVICE_Disabled		=4;

 SERVICE_Error_Ignore		=0;
 SERVICE_Error_Normal		=1;
 SERVICE_Error_Severe		=2;
 SERVICE_Error_Critical		=3;

 SERVICE_Query_Config		=$0001;
 SERVICE_Change_Config		=$0002;
 SERVICE_Query_Status		=$0004;
 SERVICE_Enumerate_Dependents	=$0008;
 SERVICE_Start			=$0010;
 SERVICE_Stop			=$0020;
 SERVICE_Pause			=$0040;
 SERVICE_Continue		=$0080;
 SERVICE_User_Defined_Control	=$0100;
 SERVICE_All_Access		=$01FF;

 SERVICE_Control_Stop		=1;
 SERVICE_Control_Pause		=2;
 SERVICE_Control_Continue	=3;
 SERVICE_Control_Interrogate	=4;
 SERVICE_Control_Shutdown	=5;
 SERVICE_Control_Paramchange	=6;
 SERVICE_Control_NetBindAdd	=7;
 SERVICE_Control_NetBindRemove	=8;
 SERVICE_Control_NetBindEnable	=9;
 SERVICE_Control_NetBindDisable	=10;

 SC_MANAGER_Connect		=$0001;
 SC_MANAGER_Create_Service	=$0002;
 SC_MANAGER_Enumerate_Service	=$0004;
 SC_MANAGER_Lock		=$0008;
 SC_MANAGER_Query_Lock_Status	=$0010;
 SC_MANAGER_Modify_Boot_Config	=$0020;
 SC_MANAGER_All_Access		=$000F003F;

 HKCU	=HKey_Current_User;		{Shortcuts}
 HKLM	=HKey_Local_Machine;
 HKU	=HKey_Users;
 HKPD	=HKey_Performance_Data;
 HKCC	=HKey_Current_Config;
 HKDD	=HKey_Dyn_Data;
const	{some flags for CreateFile()}
 GENERIC_Read		=$80000000;
 GENERIC_Write		=$40000000;
 GENERIC_Execute	=$20000000;
 GENERIC_All		=$10000000;
 FILE_Share_Read	=1;
 FILE_Share_Write	=2;
 FILE_Share_Delete	=4;
 DELETE			=$00010000;
 READ_Control		=$00020000;
 WRITE_DAC		=$00040000;
 WRITE_Owner		=$00080000;
 SYNCHRONIZE		=$00100000;
const	{new flag bit added to GetWinFlags()}
 WF_WinNT		=$4000;

implementation
function LoadLibraryEx32W;	external 'KERNEL' index 513;
function FreeLibrary32W;	external 'KERNEL' index 514;
function GetProcAddress32W;	external 'KERNEL' index 515;
function GetVDMPointer32W;	external 'KERNEL' index 516;
function CallProc32W0;		external 'KERNEL' index 517;
function CallProc32W1;		external 'KERNEL' index 517;
function CallProc32W2;		external 'KERNEL' index 517;
function CallProc32W3;		external 'KERNEL' index 517;
function CallProc32W4;		external 'KERNEL' index 517;
function CallProc32W5;		external 'KERNEL' index 517;
function CallProc32W6;		external 'KERNEL' index 517;
function CallProc32W7;		external 'KERNEL' index 517;
function CallProc32W8;		external 'KERNEL' index 517;
function CallProcEx32W;		external 'KERNEL' index 518;
end.
Detected encoding: ASCII (7 bit)2