GetModuleBaseName

 

Description

 

Retrieves the base name of the specified module.

 

C++ Syntax

 

DWORD WINAPI GetModuleBaseName(

__in     HANDLE hProcess,

__in_opt HMODULE hModule,

__out    LPTSTR lpBaseName,

__in     DWORD nSize

);

 

PowerBASIC Syntax

 

FUNCTION GetModuleBaseName ( _

BYVAL hProcess AS DWORD, _

BYVAL hModule AS DWORD, _

BYREF lpBaseName AS ASCIIZ, _

BYVAL nSize AS DWORD _

) AS DWORD

 

Unicode version:

 

FUNCTION GetModuleBaseNameW ( _

BYVAL hProcess AS DWORD, _

BYVAL lpv AS DWORD, _

BYVAL lpFilename AS DWORD, _

BYVAL nSize AS DWORD _

) AS DWORD

 

Parameters

 

hProcess

 

[in] A handle to the process that contains the module.

 

The handle must have the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights

 

hModule

 

[in, optional] A handle to the module. If this parameter is NULL, this function returns the name of the file used to create the calling process.

 

lpBaseName

 

[out] A pointer to the buffer that receives the base name of the module. If the base name is longer than maximum number of characters specified by the nSize parameter, the base name is truncated.

 

nSize

 

[in] The size of the lpBaseName buffer, in characters

 

Return Value

 

If the function succeeds, the return value specifies the length of the string copied to the buffer, in characters.

 

If the function fails, the return value is zero. To get extended error information, call GetLastError.

 

Remarks

 

The GetModuleBaseName function is primarily designed for use by debuggers and similar applications that must extract module information from another process. If the module list in the target process is not yet initialized, or if the module list changes during the function call as a result of DLLs being loaded or unloaded, GetModuleBaseName may fail or return incorrect information.

 

To retrieve the base name of a module in the current process, use the GetModuleFileName function to retrieve the full module name and then use a function call such as strrchr(szmodulename, '\\') to scan to the beginning of the base name within the module name string. This is more efficient and more reliable than calling GetModuleBaseName with a handle to the current process.

 

To retrieve the base name of the main executable module for a remote process, use the GetProcessImageFileName or QueryFullProcessImageName function to retrieve the module name and then use the strrchr function as described in the previous paragraph. This is more efficient and more reliable than calling GetModuleBaseName with a NULL module handle.

 

The GetModuleBaseName function does not retrieve the base name for modules that were loaded with the LOAD_LIBRARY_AS_DATAFILE flag. For more information, see LoadLibraryEx.

 

Valid XHTML 1.0 Transitional