Beispiel #1
0
        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));
                }
        }
Beispiel #2
0
        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));
                }
        }
Beispiel #3
0
        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));
                }
        }
Beispiel #4
0
 public unsafe static extern bool GetModuleHandleExW(
     GetModuleFlags dwFlags,
     IntPtr lpModuleName,
     out IntPtr moduleHandle);