LoadModule

Version 3.0

Syntax

HANDLE LoadModule(lpModuleName,lpParameterBlock)

This function loads and executes a Windows program or creates a new instance of an existing Windows program.

Parameter Type/Description  

lpModuleName LPSTR Points to a null-terminated string that contains the filename of the application to be run. If the lpModuleName string does not contain a directory path, Windows will search for the executable file in this order:  
  1.The current directory  
  2.The Windows directory (the directory containing WIN.COM); the GetWindowsDirectory function obtains the pathname of this directory  
  3.The Windows system directory (the directory containing such system files as KERNEL.EXE); the GetSystemDirectory function obtains the pathname of this directory  
  4.The directories listed in the PATH environment variable  
  5.The list of directories mapped in a network  
If the application filename does not contain an extension, then .EXE is assumed.  
lpParameterBlock LPVOID Points to a data structure consisting of four fields that defines a parameter block. This data structure consists of the following fields:  
  Field Type/Description
  wEnvSeg WORD Specifies the segment address of the environment under which the module is to run; 0 indicates that the Windows environment is to be copied.
  lpCmdLine LPSTR Points to a null-terminated character string that contains a correctly formed command line. This string must not exceed 120 bytes in length.
Parameter Type/Description  

  Field Type/Description
  lpCmdShow LPVOID Points to a data structure containing two WORD-length values. The first value must always be set to two. The second value specifies how the application window is to be shown. See the description of the nCmdShow paramter of the ShowWindow function for a list of the acceptable values.
  dwReserved DWORD Is reserved and must be NULL.
  All unused fields should be set to NULL, except for lpCmdLine, which must point to a null string if it is not used.  

Return Value

The return value identifies the instance of the loaded module if the function was successful. Otherwise, it is a value less than 32 that specifies the error. The following list describes the error values returned by this function:

Value Meaning

0 Out of memory.
2 File not found.
3 Path not found.
5 Attempt to dynamically link to a task.
6 Library requires separate data segments for each task.
10 Incorrect Windows version.
11 nvalid .EXE file (non-Windows .EXE or error in .EXE image).
12 OS/2 application.
13 DOS 4.0 application.
Value Meaning

14 Unknown .EXE type.
15 Attempt in protected (standard or 386 enhanced) mode to load an .EXE created for an earlier version of Windows.
16 Attempt to load a second instance of an .EXE containing multiple, writeable data segments.
17 Attempt in large-frame EMS mode to load a second instance of an application that links to certain nonshareable DLLs already in use.
18 Attempt in real mode to load an application marked for protected mode only.

Comments

The WinExec function provides an alternative method for executing a program.