Kernel32GetModuleHandleEx Method

Retrieves a module handle for the specified module and increments the module's reference count unless UnchangedReferenceCount flag is specified.

The module must have been loaded by the calling process.

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.Ansi, BestFitMapping = false, 
	ThrowOnUnmappableChar = true, SetLastError = true)]
public static bool GetModuleHandleEx(
	GetModuleHandleExFlags flags,
	[OptionalAttribute] string moduleName,
	out IntPtr refModule
)

Parameters

flags  GetModuleHandleExFlags
Flags that determines the load behavior.

If the module's reference count is incremented, the caller must use the FreeLibrary(SafeModuleHandle) function to decrement the reference count when the module handle is no longer needed.

moduleName  String  (Optional)
The name Of the loaded Module (either a .dll Or .exe file), Or an address In the Module (If flags Is FromAddress).

For a module name, if the file name extension Is omitted, the default library extension .dll Is appended.

The file name string can include a trailing point character (.) To indicate that the Module name has no extension.

The String does Not have To specify a path. When specifying a path, be sure To use backslashes (\), Not forward slashes (/).

The name Is compared (Case independently) To the names Of modules currently mapped into the address space Of the calling process.

If this parameter Is , the Function returns a handle To the file used To create the calling process (.exe file).

refModule  IntPtr
A handle to the specified module. If the function fails, this parameter is Zero.

The GetModuleHandleEx(GetModuleHandleExFlags, String, IntPtr) function does not retrieve handles for modules that were loaded using the LoadLibraryAsDataFile flag.

Return Value

Boolean
If the function succeeds, the return value is .

If the function fails, the return value is .

To get extended error information, call GetLastWin32Error.

Remarks

See Also