Kernel32GetModuleFileName Method

Retrieves the fully qualified path for the file that contains the specified module. The module must have been loaded by the current process.

To locate the file for a module that was loaded by another process, use the GetModuleFileNameEx(IntPtr, IntPtr, StringBuilder, UInt32) function.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, BestFitMapping = false, 
	ThrowOnUnmappableChar = true, SetLastError = true)]
public static uint GetModuleFileName(
	IntPtr hModule,
	StringBuilder filename,
	uint size
)

Parameters

hModule  IntPtr
A handle to the loaded module whose path is being requested.

If this parameter is , GetModuleFileName(IntPtr, StringBuilder, UInt32) retrieves the path of the executable file of the current process.

The GetModuleFileName(IntPtr, StringBuilder, UInt32) function does not retrieve the path for modules that were loaded using the LoadLibraryAsDataFile flag.

filename  StringBuilder
A pointer to a buffer that receives the fully qualified path of the module.

If the length of the path is less than the size that the size parameter specifies, the function succeeds and the path is returned as a null-terminated string.

size  UInt32
The size of the filename buffer.

Return Value

UInt32
If the function succeeds, the return value is the length of the string that is copied to the buffer, in characters, not including the terminating null character.

If the buffer is too small to hold the module name, the string is truncated to size characters including the terminating null character, the function returns size, and the function sets the last error to ERROR_INSUFFICIENT_BUFFER.

If size is zero, the return value is 0 (zero) and the last error code is ERROR_SUCCESS.

If the function fails, the return value is 0 (zero).

To get extended error information, call GetLastWin32Error.

Remarks

See Also