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); }
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); }
public void CreateTest() { string input = @"../../libtest.dll"; try { using (dynamic native = NativeFactory.Create(input, CallingConvention.ThisCall)) { } } catch { throw; } }
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; } }
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); }
/*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)); }