一个.dll文件内容:
namespace PubFunction
{
public class PubFunction
{
//****************程序退出*********************
public static void ExitSys()
{
Application.Exit();
}
}
}
现在我的c#程序test.cs中添加引用了这个.dll之后,
PubFunction.PubFunction a = new PubFunction.PubFunction();
Type type = a.GetType();
MethodInfo method = type.GetMethod( "ExitSys");
method.Invoke(a , null);
报参数计数不匹配.而把
public static void ExitSys()
{
Application.Exit();
}
放到程序test.cs的类中则没有错误,参数请问到底是怎么回事呀?
namespace PubFunction
{
public class PubFunction
{
//****************程序退出*********************
public static void ExitSys()
{
Application.Exit();
}
}
}
现在我的c#程序test.cs中添加引用了这个.dll之后,
PubFunction.PubFunction a = new PubFunction.PubFunction();
Type type = a.GetType();
MethodInfo method = type.GetMethod( "ExitSys");
method.Invoke(a , null);
报参数计数不匹配.而把
public static void ExitSys()
{
Application.Exit();
}
放到程序test.cs的类中则没有错误,参数请问到底是怎么回事呀?
//using System.Reflection;
//生成一个MyDll的项目,里面包含一个Form1,编译为dll
//mydll.dll放到当前目录下
Assembly asm = AppDomain.CurrentDomain.Load("MyDll");
Type tp = asm.GetType("MyDll.Form1");
object o = Activator.CreateInstance(tp);
MethodInfo mi = tp.GetMethod("Show");
mi.Invoke(o,null);
我刚刚学c#呀,很多基本的东西还处于模糊状态,特别c#跟以前语言有些本质上的概念区别,好难啊。
Assembly assem = Assembly.LoadFrom("f:\\PubLib.dll");
Type type = assem.GetType("PubFunction.PubFunction");
MethodInfo method = type.GetMethod( "ExitSys");
Object obj = Activator.CreateInstance(type);
method.Invoke(obj,null);PubLib.dll中ExitSys是这样的,没有任务参数。
public static void ExitSys()
{
Application.Exit();
}但执行时还是报:参数计数不匹配出错行是:method.Invoke(obj,null);救命啊!!!!我搞了整整2天了都。 :(
原因在于:Application.Exit();
如果ExitSys是:
public static void ExitSys()
{
MessageBox.Show("hi");
}
可以正常的运行。当初建立PubLib.dll时,项目类型是windows控件库,那么运行Application.Exit()时,可能会找不到exit哪个form吧。
那么如果一定要用.dll的话,这个问题如何解决呀?
另外一个新的问题:
如果我的ExitSys()要带参数那该怎么办呀??
int iCount = img_gif.GetFrameCount(dimension);
int iFrameIndex = 3;//你想看的某祯画面
img_gif.SelectActiveFrame(dimension,iFrameIndex );
img_gif.Save("f:\\aa1.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);System.Drawing.Image img = new Bitmap("f:\\aa1.jpg");
System.Drawing.Graphics gp = Graphics.FromImage(img);Font myFont = new Font("黑体",16,FontStyle.Bold);
SolidBrush mySolidBrush = new SolidBrush(Color.Red);
PointF myPointF = new PointF(50,160);
gp.SmoothingMode = SmoothingMode.AntiAlias;
gp.DrawString("MY IMAGE",myFont,mySolidBrush,myPointF);//img.Save(Response.OutputStream,ImageFormat.Gif);img.Save("f:\\girl_pic.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);img_gif.FrameDimensionsList
gp.Dispose();
img.Dispose();
----------------------------------------------------------------------
img_gif.FrameDimensionsList 这里代码不全
//1.cs
using System;
using System.Windows.Forms;
namespace PubFunction
{
public class PubFunction
{
public static void ExitSys()
{
Application.Exit();
}
}
}//test.cs
using System;
using System.Reflection;namespace test
{
/// <summary>
/// e 的摘要说明。
/// </summary>
public class e
{
public static void Main(string[] args)
{
Assembly assem = Assembly.LoadFrom("1.dll");
Type type = assem.GetType("PubFunction.PubFunction");
MethodInfo method = type.GetMethod( "ExitSys");
Object obj = Activator.CreateInstance(type);
Console.ReadLine();
method.Invoke(obj,null);
}
}
}
我用记事本写的1.cs用csc 1.cs编译不能通过呀。????