示例#1
0
        public void DynamicFunction()
        {
            int input  = 0;
            int result = -1;

            using (dynamic native = NativeFactory.Create(@"../../libtest.dll"))
            {
                result = native.test <int>(input);
            }

            Assert.AreEqual(input, result);
        }
示例#2
0
        public void AutoFunction()
        {
            int input  = 0;
            int result = -1;

            using (var native = NativeFactory.Create(@"../../libtest.dll"))
            {
                result = native.Invoke <int>("test", input);
            }

            Assert.AreEqual(input, result);
        }
示例#3
0
        public void CreateTest()
        {
            string input = @"../../libtest.dll";

            try
            {
                using (dynamic native = NativeFactory.Create(input, CallingConvention.ThisCall))
                {
                }
            }
            catch
            {
                throw;
            }
        }
示例#4
0
        public void CallingConventionFunction()
        {
            string input = @"../../libtest.dll";

            try
            {
                using (var native = NativeFactory.Create(input))
                {
                    var result = native.Invoke <int>("test", CallingConvention.StdCall, input);
                }
            }
            catch
            {
                throw;
            }
        }
示例#5
0
        public void DelegateFunction()
        {
            int input  = 0;
            int result = -1;

            using (var native = NativeFactory.Create(@"../../libtest.dll"))
            {
                using (var native1 = NativeFactory.Create(@"../../libtest.dll"))
                {
                    var result1 = native1.Invoke <int, Test>(input);

                    var test = native1.GetFunction <Test>();
                    result = test(input);
                }
            }

            Assert.AreEqual(input, result);
        }
示例#6
0
        /*protected TDel FindFunction<TDel>(string name, bool exact) where TDel : class
         * {
         *      if(hmod == IntPtr.Zero) return null;
         *      IntPtr proc = Native.GetProcAddress(hmod, name);
         *      if(proc == IntPtr.Zero)
         *      {
         *              if(exact) throw new Win32Exception();
         *              proc = FindProcMangled(name);
         *      }
         *
         *      return Marshal.GetDelegateForFunctionPointer<TDel>(proc);
         * }*/

        public static T Create <T>(string lib) where T : NativeLibrary
        {
            return(NativeFactory <T> .Create(lib));
        }