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>loadlibrary()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
LoadLibrary()
Load a library (DLL)
------------------------------------------------------------------------------

Syntax
LoadLibrary( <cLibrary> )   -->   hLibrary

Arguments
<cLibrary> is a string specifying the library.  Normally this
has a ".DLL" extension, but others are used (e.g. ".DRV", ".EXE").

Returns
The returned value is an integer specifying the handle to the
instance of the library, or an integer error code (if the
value is less than 32).

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

If the <cLibrary> parameter does not specify a path to the
library, Windows tries the current directory, then the Windows
directory (as returned by the GetWindowsDirectory()
function), then the Windows system directory (as returned by
the GetSystemDirectory() function), then the directory
containing the application issuing the WinExec() call, then
the directories in the PATH, and finally any network-mapped
directories.

If successful, this function increases the DLL's reference
count by one.  The related function FreeLibrary() decreases
the count.  (The count determines when Windows must load a
library, and when it can be unloaded.)

The error codes are as follows:

    <hLibrary>      means

          0         out of memory, or invalid executable file

          2         program not found

          3         invalid path

          5         sharing or network violation

          6         a library error

          8         out of memory

          10        wrong Windows version for the application

          11        invalid executable file

          12        wrong operating system for application

          13        MS-DOS 4.0 only application

          14        unknown executable file version

          15        a real-mode Windows application

          16        attempt to run multiple copies of an
                    application with multiple data segments

          19        trying to run a compressed executable file

          20        a required DLL was invalid (corrupt)

          21        32-bit Windows extensions required

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
CallDLL( cRectangle, hDC, 10, 10, 300, 300 )   // see also Rectangle()
FreeLibrary( hLib )


See Also: CallDLL() FreeLibrary() GetProcAddress()

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