Home   Index   About
Ultimate Pack


Custom Search
Overview
Group
Quick Info

Windows NT
Yes
Win95
Yes
Win32s
Yes
Import Library
kernel32.lib
Header File
winbase.h
Unicode
No
Platform Notes
None

LoadModule

The LoadModule function loads and executes a Windows-based application or creates a new instance of an existing Windows-based application.

This function is provided for compatibility with earlier versions of Windows. Win32-based applications should use the CreateProcess function.

DWORD LoadModule(

LPCSTR lpModuleName,
// address of filename to load
LPVOID lpParameterBlock
// address of parameter block for new module
);

Parameters

lpModuleName

Points to a null-terminated string that contains the filename of the application to run. If the lpModuleName parameter does not contain a directory path, Windows searches for the executable file in this order:

  1. The directory from which the application loaded.

  2. The current directory.

  3. Windows 95: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32.

  1. Windows NT: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM.

  2. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.

  3. The directories that are listed in the PATH environment variable.

lpParameterBlock

Points to an application-defined LOADPARMS32 structure that defines the new application's parameter block.

The LOADPARMS32 structure has the following form:

typedef struct tagLOADPARMS32 {

LPSTR lpEnvAddress; // address of environment strings

LPSTR lpCmdLine; // address of command line

LPSTR lpCmdShow; // how to show new program

DWORD dwReserved; // must be zero

} LOADPARMS32;

Member
Description
lpEnvAddress
Points to an array of null-terminated strings that supply the environment strings for the new process. The array has a value of NULL as its last entry. A value of NULL for this parameter causes the new process to start with the same environment as the calling process.
lpCmdLine
Points to a Pascal-style string that contains a correctly formed command line. The first byte of the string contains the number of bytes in the string. The remainder of the string contains the command line arguments, excluding the name of the child process. If there are no command line arguments, this parameter must point to a zero length string; it cannot be NULL.
lpCmdShow
Points to a structure containing two WORD values. The first value must always be set to two. The second value specifies how the application window is to be shown and is used to supply the wShowWindow member of the STARTUPINFO structure to the CreateProcess function. See the description of the nCmdShow parameter of the ShowWindow function for a list of acceptable values.
dwReserved
This parameter is reserved; it must be zero.

Set all unused members to NULL, except for lpCmdLine, which must point to a null-terminated string if it is not used.

Return Values

If the function succeeds, the return value is greater than 31.

If the function fails, the return value is an error value, which may be one of the following:

Value
Meaning
0
The system is out of memory or resources.
ERROR_BAD_FORMAT
The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
ERROR_FILE_NOT_FOUND
The specified file was not found.
ERROR_PATH_NOT_FOUND
The specified path was not found.

Remarks

Win32-based applications should use the CreateProcess function. In the Win32 API, the implementation of the LoadModule function calls CreateProcess. The following section describes how each parameter for CreateProcess is formed:

CreateProcess parameter
Value
lpszImageName
LoadModule lpModuleName parameter.
lpszCommandLine
LoadModule lpParameterBlock->lpCmdLine.
lpsaProcess
NULL.
lpsaThread
NULL.
fInheritHandles
FALSE.
fdwCreate
0.
lpvEnvironment
LoadModule lpParameterBlock->lpEnvAddress.
lpszCurDir
NULL.
lpsiStartInfo
The structure is initialized to zero. The cb member is set to the size of the structure, and the wShowWindow member is set to the value of the second word of the LoadModule lpParameterBlock->lpCmdShow parameter.
lppiProcInfo.hProcess
The handle is immediately closed.
lppiProcInfo.hThread
The handle is immediately closed.

See Also

CreateProcess
, GetSystemDirectory, GetWindowsDirectory, ShowWindow, STARTUPINFO, WinExec


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro!  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »


All the contacts and projects

Dmitry Vasiliev (just.dmitry)

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2011 Free Tech Secrets ;) greatis just4fun network just4fun