Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide to Clip-4-Win version 3.0 - <b>getprocaddress()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
GetProcAddress()
Get access information for a function in a DLL
------------------------------------------------------------------------------

Syntax
GetProcAddress( [ <hLibrary> ] , [ <cFunction> | <nOrdinal> ] ,
                <cLanguage>, <cResultType>,
                [ <cParamInfo> ] )   -->  cProc

Arguments
<hLibrary> is an optional handle to the library containing the
function.  If this parameter is omitted (NIL), Clip-4-Win will
search the following in order: USER.EXE, GDI.EXE, KERNEL.EXE,
COMMDLG.DLL, SHELL.DLL, TOOLHELP.DLL, VER.DLL, MMSYSTEM.DLL,
LZEXPAND.DLL, DDEML.DLL, CTL3D.DLL, and BWCC.DLL.  It's
debatable whether this is a good idea, but it can be
convenient as it saves having to call LoadLibrary().

<cFunction> is an optional string specifying the name of the
function.

<nOrdinal> is an optional integer specifying the function by
its ordinal value.

<cLanguage> is a string specifying the calling convention to
use when the function is called using the CallDLL() function.
Almost all DLL functions use the "Pascal" convention.
Currently the only alternative is "C".

<cResultType> is a string specifying the type of the value (if
any) returned by the function.  Supported types are: the 16-
bit types "integer", "word", "uint", "handle" (and equivalents
hwnd, hinstance, hdc, hmenu, htask, hbitmap, etc.), "atom";
the 32-bit types "long", "ulong", "dword", "colorref"; the 32-
bit floating point types "float" and "real"; the 64-bit
floating point type "double"; the string types (all returned
up to the null character) "string", "character", "char*",
"LPSTR", "LPCSTR", "LPVOID", "void*"; "logical" or "boolean";
"nil", "void", or "none".  You only need enough characters to
make the type unique, and the distinction between upper and
lower case is ignored.

<cParamInfo> is an optional string specifying the type of each
parameter the function expects.  If this parameter is omitted,
the function should expect no parameters.  The <cParamInfo>
string should be a comma-separated list, with each type being
one of the types allowed for <cResultType> or: "byte" (you
pass a small numeric, which is actually passed in 16 bits);
the string types (all passed as a pointer) "string",
"character", "char*", "LPSTR", "LPCSTR", "LPVOID", "void*";
and pointer to array of pointers (you pass an array of Clipper
strings) "char**", "void**", "string*", "LPSTR*", or
"LPCSTR*".  You only need enough characters to make the type
unique, and the distinction between upper and lower case is
ignored.

There are still a few parameters that cannot be described by
the above.  Sorry, you'll have to write a small C function!

Returns
If successful, a character string describing the DLL function
is returned.  The encoding of this string may change in the
future, and is deliberately undocumented.  If an error is
detected, NIL is returned (see below).

If you're having problems, proceed as follows.  NIL means one
of your parameters is wrong or the function wasn't found.  A
string means your parameters passed the tests for validity and
the function was found.  However, your parameters may be
describing the function incorrectly, in which case a General
Protection Fault (GPF) is the most likely result when you
later use CallDLL().

Description
This function and the related functions LoadLibrary() and
CallDLL() can be used to access dynamic link libraries
(DLL's).

If you want to call a function with different numbers of
parameters, or with different parameter types, you will need
to use GetProcAddress() for each of the possibilities.  For
examples, see source\winapi\menu.prg.

Other useful files can be found in source\, source\contrib\,
and there's also the now-obsolete file source\gs\gs.prg.

Example
hLib = LoadLibrary( "KERNEL.EXE" )      // part of Windows
// This one returns a long (32-bit number), and has no params:
cGetWinFlags = GetProcAddress( hLib, 132, "Pascal", "Long")
? CallDLL( cGetWinFlags )               // see also GetWinFlags()
FreeLibrary( hLib )

hLib = LoadLibrary( "GDI.EXE" )                   // part of Windows
cRectangle = GetProcAddress( hLib, "rectangle",  ;  // get by name
                   "Pascal", "int",          ;   // Pascal, returns int
                   "int, int, int, int, int" )   // 5 int params
cRectangl2 = GetProcAddress( hLib, 27,       ;   // ordinal number
                   "Pascal", "Int",          ;   // Pascal, returns int
                   "int, int, int, int, int" )   // 5 int params
// this one isn't true (it doesn't use C calling convention):
// cRectanglC = GetProcAddress( hLib, 27, "C",   ;
//                    "Int", "int,int, int, int, int")

hDC = GetDC( hWnd )
CallDLL( cRectangle, hDC, 10, 10, 300, 300 )     // or use cRectangl2
ReleaseDC( hWnd, hDC )
FreeLibrary( hLib )


See Also: CallDLL() FreeLibrary() LoadLibrary()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson