反射dll里的函数
来源:互联网 发布:乔丹史兰斯基 知乎 编辑:程序博客网 时间:2024/05/21 12:06
生成dll的程序
备注
调用时不需要引用dll文件
http://blog.csdn.net/bdstjk/article/details/7535230
例子1种必须实例化反射要反射的类,因为要使用的方法并不是静态方法
例子2种我们想用的方法是一个静态方法,这时候Invoke的时候,对于第一个参数是无视的
第三个例子是一个调用无参数静态方法的例子,这时候两个参数我们都不需要指定,用null就可以了
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ReflectionTest{ public class WriteTest { //public method with parametors public void WriteString(string s, int i) { Console.WriteLine("WriteString:" + s + i.ToString()); } //static method with only one parametor public static void StaticWriteString(string s) { Console.WriteLine("StaticWriteString:" + s); } //static method with no parametor public static void NoneParaWriteString() { Console.WriteLine("NoParaWriteString"); } }}
反射调用dll函数的程序
<pre name="code" class="csharp">using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Reflection;class TestApp{ public static void Main() { Assembly ass; Type type; Object obj; Object any = new Object(); ass = Assembly.LoadFile(@"F:\1Test\ReflectTest\ReflectTest\bin\Debug\ReflectTest.dll");//dll文件的绝对路径 type = ass.GetType("ReflectionTest.WriteTest");//命名空间.类名 /*example1---------*/ MethodInfo method = type.GetMethod("WriteString"); string test = "test"; int i = 1; Object[] parametors = new Object[] { test, i }; obj = ass.CreateInstance("ReflectionTest.WriteTest"); method.Invoke(obj,//Instance object of the class need to be reflect parametors); //method.Invoke(any, parametors);//RuntimeError: class reference is wrong /*example2----------*/ method = type.GetMethod("StaticWriteString"); method.Invoke(null, new string[] { "test" }); method.Invoke(obj, new string[] { "test" }); method.Invoke(any, new string[] { "test" }); /*example3-----------*/ method = type.GetMethod("NoneParaWriteString"); method.Invoke(null, null); }}
备注
调用时不需要引用dll文件
http://blog.csdn.net/bdstjk/article/details/7535230
例子1种必须实例化反射要反射的类,因为要使用的方法并不是静态方法
例子2种我们想用的方法是一个静态方法,这时候Invoke的时候,对于第一个参数是无视的
第三个例子是一个调用无参数静态方法的例子,这时候两个参数我们都不需要指定,用null就可以了
0 0
- 反射dll里的函数
- 动态加载MATLAB生成的dll并反射dll里的函数
- 动态加载MATLAB生成的dll并反射dll里的函数,实现多返回值的功能
- DLL回调EXE里的函数
- 简单使用DLL里的函数
- DLL学习——使用DLL里的导出函数
- 关于java调用window DLL里的函数的总结
- 取.dll文件里的函数的地址;
- JAVA里如何调用C/C++的DLL里的函数
- 如何调试反射的dll
- 生成/创建 DLL 及调用/引用DLL里的函数、全局变量、静态C++类成员函数等
- java里的反射机制
- 在mfc的dll里再动态加载jvm.dll引发的问题--不要在构造函数里做复杂的init流程
- MFC扩展dll里导出函数时资源切换的问题
- MFC扩展dll里导出函数时资源切换的问题
- 构造函数的反射
- (.net) 使用反射获得 dll 的 HINSTANCE
- 关于反射加载DLL的问题2
- Android 用户界面---操作栏(Action Bar 一)
- C++实验2-利用循环求和
- 基于opencv和QT的人脸(人眼)检测程序
- C++实验4-百钱百鸡问题
- servlet/filter/listener/interceptor区别与联系
- 反射dll里的函数
- ubuntu下ndnsim1.0的安装
- C#基础知识之自定义类
- proxychains-3.1 在CENTOS 7上安装使用方法
- c++第四次实验 -利用循环求和
- 百度坐标转高德坐标(也就是火星坐标)
- c++第四次上机报告
- [IOS/翻译]Media Layer
- 【网络安全】复习网络安全相关内容