DWORD LoadModule(lpszModule, lpvParamBlock) | |||||
LPCSTR lpszModule; | /* address of filename to load | */ | |||
LPVOID lpvParamBlock; | /* address of parameter block for new module | */ |
The LoadModule function loads and executes a Windows application or creates a new instance of an existing Windows application.
This function is obsolete. Applications should use the CreateProcess function. The Win32 implementation of the LoadModule function calls the CreateProcess function. The following section describes how each parameter for the CreateProcess function is formed:
CreateProcess parameter | Value |
lpApplicationName | LoadModule lpszModule parameter |
lpCommandLine | LoadModule lpvParamBlock->lpCmdLine |
lpProcessAttributes | NULL |
lpThreadAttributes | NULL |
bInheritHandles | FALSE |
dwCreationFlags | 0 |
lpEnvironment | LoadModule lpvParamBlock->lpEnvAddress |
lpCurrentDirectory | NULL |
lpStartupInfo | The structure is initialized to zero. The cb field is set to the size of the structure, and the wShowWindow field is set to the value of the second word of the LoadModule lpvParamBlock->lpCmdShow parameter. |
lpProcessInformation.hProcess | The handle is immediately closed. |
lpProcessInformation.hThread | The handle is immediately closed. |
lpszModule
Points to a null-terminated string that contains the filename of the application to run. If the lpszModule string does not contain a directory path, Windows will search for the executable file in this order:
1.The current directory
2.The Windows system directory (the directory containing such system files as KERNEL.EXE); the GetSystemDirectory function obtains the pathname of this directory
3.The Windows directory (the directory containing WIN.COM); the GetWindowsDirectory function obtains the pathname of this directory
4.The directories listed in the PATH environment variable
lpvParamBlock
Points to a LOADPARMS32 structure that defines the new program'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 null-terminated string that contains a correctly formed command line. | ||
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 dwShowWindow parameter to CreateProcess. See the description of the nCmdShow parameter of the ShowWindow function for a list of the acceptable values. | ||
dwReserved | ||
This parameter is reserved. It must be zero. |
All unused fields should be set to NULL, except for lpCmdLine, which must point to a null string if it is not used.
The return value is 32 if the function was successful. Otherwise, it is an error code, which may be one of the following:
Value | Meaning |
0 | Out of memory or system resources. |
2 | File not found. |
3 | Path not found. |
11 | Invalid .EXE file (non-32-bit Windows .EXE or error in .EXE image). |
CreateProcess, GetSystemDirectory, GetWindowsDirectory, ShowWindow, WinExec