LoadLibrary()

Summary

Loads a DLL and returns a handle that can be used in function calls.

Changes

Added in Version 6.0/2012.

Syntax

dllhandle = LoadLibrary(string dll_name [, array options])

Argument Contents
dll_name The name of the Dynamic Link Library (DLL)
Option Type Contents
StdCall Boolean If "true" assumes the _stdcall calling convention, where arguments are passed on the stack and the called function is responsible for removing them off the stack; default is "false"
FastCall Boolean If "true" assumes the _fastcall calling convention, where some arguments are passed in registers and the called function is responsible for popping other arguments off the stack; default is "false"
Cdecl Boolean Assumes the _cdecl calling convention, where the arguments are passed on the stack and the calling function is responsible for removing them off the stack; default is "true"
Return Type String Can be "double", "int" or "string"

Returns

A DLL handle.

Notes

  • The options array is an optional argument.

  • The dll remains loaded until the variable is discarded.

  • In 64-bit programs the calling convention option is ignored, since all 64-bit programs use the equivalent of the FastCall calling convention.

  • In a 32-bit environment, all Standard Windows API functions use StdCall.

Example

// You can use this to hook into Windows API. Take for an example:
//
// int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
//
// declared in user32.dll. You would actually call the MessageBoxA version with
hDll = LoadLibrary("user32.dll")
args = {{"long",0},{"char *","Hello World"},{"char *","My Title"},{"long",0}}
opts.StdCall = "True"
opts.[Return Type] = "long"
ret = hDll.MessageBoxA(args, opts)

Error Codes

Error Type Meaning
Error An invalid parameter was specified
NotFound The DLL or one of its required components was not found or could not be loaded

See Also

Function Summary
CallDllFunction() Calls a function in a Dynamic Link Library (DLL)
LaunchProgram() Starts a Windows program
LaunchDocument() Open a document, executable, or URL with the appropriate program