补充对Keyes的代码的说明:
The intention of this posting is to show a way of how to access 16 bit
DLLs out of an application developed in Delphi 2. A few days ago i
posted a message in delphi.misc to show the usage of undocumented
functions inside Kernel32.dll. Especially there are four of interest:
LoadLibrary16, GetProcAddress16, FreeLibrary16 and VxDCall0. With the
help of these functions, you can load and free 16bit libraries and get
the virtual address of a procedure inside a dll.
But there are some problems: kernel32 does not export undocumented
functions by name or ordinal. The only way to solve this was to read
and understand the internal PE(portable executable) format
specification. The PE format is used by 32bit apps and dlls. By
examining this format, you will find an export table with the absolute
offset of each function inside. Combined with the virtual module
address in memory, you get the virtual starting point of an
undocumented function. This does the function GetProcAdress32.
The next problem: 16bit functions/apps are using a different kind of
addressing (segment
ffset) and have their own address space/stack
inside Win95, which "emulates" a 16bit os. To call a 16bit function
out of a 32bit application, you have to "build" a 16bit stack and to
do some other work -) . This does a kernel32 function named
'QT_Thunk'. With the help of some lines of inline assembler, you push
your arguments on the stack, push the virtual address of your 16bit
function in the register edx and call QT_Thunk. The return values can
be found in several registers. The example uses the
GetFreeSystemResources inside (the 16bit) user.exe and works fine.
Some comments: This source is free but without any guarantees! I would
like to get responses about the implementation of my code in yours.
The implementation of the thunk mechanism inside the asm statement was
taken from an example of Tempest Software, but i do not accept their
copyright, since their piece of code does *not* work and uses no
special algorithms (only some WIN API calls)! The information about
accessing undocumented functions was taken from Andrew Schulmans
"Undocumented Windows" and "Unautherized Windows". Great books! If you
have problems with getting this code to run mail me, i will send you a
copy of my complete source as attachment.