[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path of the executable file of the current process.
[out] Pointer to a buffer that receives a null-terminated string that specifies the fully-qualified path of the module. If the length of the path exceeds the size that the nSize parameter specifies, the function succeeds, and the string is truncated to nSize characters and cannot be null terminated.
The string returned will use the same format that was specified when the module was loaded. Therefore, the path can be a long or short file name, and can use the prefix "\\?\". For more information, see Naming a File.
To separate the path from the file name and extension, use the PathRemoveFileSpec function. Note that this function does not support paths with the "\\?\" prefix.
[in] Size of the lpFilename buffer, in TCHARs.
If the function succeeds, the return value is the length of the string that is copied to the buffer, in TCHARs. If the buffer is too small to hold the module name, the string is truncated to nSize, and the function returns nSize.
If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError.
If a DLL is loaded in two processes, its file name in one process may differ in case from its file name in the other process.
For the ANSI version of the function, the number of TCHARs is the number of bytes; for the Unicode version, it is the number of characters.
The global variable _pgmptr is automatically initialized to the full path of the executable file, and can be used to retrieve the full path name of an executable file.
Windows Me/98/95: This function retrieves long file names when an application version number is greater than or equal to 4.00 and the long file name is available. Otherwise, it returns only 8.3 format file names.
For an example, see Installing a Service.
Client Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header Declared in Winbase.h; include Windows.h.
Library Link to Kernel32.lib.
DLL Requires Kernel32.dll.
Unicode Implemented as GetModuleFileNameW (Unicode) and GetModuleFileNameA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
Dynamic-Link Library Functions, GetModuleFileNameEx, GetModuleHandle, LoadLibrary