예제 #1
0
        public static Delegate GetDelegate(IntPtr hLib, Type delegateType)
        {
#if USE_GETFUNCTIONLIST
            CK_FUNCTION_LIST flist = GeFunctionList(hLib);
            IntPtr           fp    = (IntPtr)flist.GetType().GetField(delegateType.Name).GetValue(flist);
            if (fp == IntPtr.Zero)
            {
                throw new Exception("Bad pointer to " + delegateType.Name + " function.");
            }
#else
            IKernelUtil ker = null;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                ker = new KernelUtilWindows();
            }
            else
            {
                ker = new KernelUtilUNIX();
            }

            IntPtr fp = ker.GetProcAddress(hLib, delegateType.Name);
            if (fp == IntPtr.Zero)
            {
                throw new Exception(delegateType.Name + " could not be found");
            }
#endif


            return(Marshal.GetDelegateForFunctionPointer(fp, delegateType));
        }
예제 #2
0
        public static Delegate GetDelegate(IntPtr hLib, Type delegateType)
        {
                        #if USE_GETFUNCTIONLIST
            CK_FUNCTION_LIST flist = GeFunctionList(hLib);
            IntPtr           fp    = (IntPtr)flist.GetType().GetField(delegateType.Name).GetValue(flist);
            if (fp == IntPtr.Zero)
            {
                throw new Exception("Bad pointer to " + delegateType.Name + " function.");
            }
                        #else
            IntPtr fp = KernelUtil.GetProcAddress(hLib, delegateType.Name);
            if (fp == IntPtr.Zero)
            {
                throw new Exception(delegateType.Name + " could not be found");
            }
                        #endif

            return(Marshal.GetDelegateForFunctionPointer(fp, delegateType));
        }