예제 #1
0
        //  ------------------
        //  GetFunction method
        //  ------------------

        internal static T GetFunction <T>(this NativeLibraryHandle library, string procName, ref T function) where T : class
        {
            if (function == null)
            {
                var address = NativeMethods.GetProcAddress(library, procName);
                if (address == IntPtr.Zero)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
                function = Marshal.GetDelegateForFunctionPointer(address, typeof(T)) as T;
            }
            return(function);
        }
 internal static extern IntPtr GetProcAddress(NativeLibraryHandle handle, [MarshalAs(UnmanagedType.LPStr)] string procName);