private static unsafe IntPtr GetModuleHandleHelper(string moduleName, GetModuleFlags flags) { IntPtr GetHandle(IntPtr n, GetModuleFlags f) { Error.ThrowLastErrorIfFalse( Imports.GetModuleHandleExW(f, n, out var handle), moduleName); return(handle); } if (moduleName == null) { return(GetHandle(IntPtr.Zero, flags)); fixed(void *name = moduleName) { return(GetHandle((IntPtr)name, flags)); } }
private unsafe static IntPtr GetModuleHandleHelper(string moduleName, GetModuleFlags flags) { Func <IntPtr, GetModuleFlags, IntPtr> getHandle = (IntPtr n, GetModuleFlags f) => { if (!Imports.GetModuleHandleExW(f, n, out var handle)) { throw Error.GetExceptionForLastError(); } return(handle); }; if (moduleName == null) { return(getHandle(IntPtr.Zero, flags)); fixed(void *name = moduleName) { return(getHandle((IntPtr)name, flags)); } }
private unsafe static ModuleHandle GetModuleHandleHelper(string moduleName, GetModuleFlags flags) { Func <IntPtr, GetModuleFlags, ModuleHandle> getHandle = (IntPtr n, GetModuleFlags f) => { ModuleHandle handle; if (!Direct.GetModuleHandleExW(f, n, out handle)) { throw ErrorHelper.GetIoExceptionForLastError(); } return(handle); }; if (moduleName == null) { return(getHandle(IntPtr.Zero, flags)); fixed(void *name = moduleName) { return(getHandle((IntPtr)name, flags)); } }
public unsafe static extern bool GetModuleHandleExW( GetModuleFlags dwFlags, IntPtr lpModuleName, out IntPtr moduleHandle);