try it:string s = "fqq"; Type t = Type.GetTypeFromProgID("SecurityToolkit.KeyManager"); object obj = Activator.CreateInstance(t); object[] args = new object[]{s}; ParameterModifier m = new ParameterModifier(1); m[0] = true; ParameterModifier[] pma = {m}; object result = t.InvokeMember("GenerateKey",BindingFlags.InvokeMethod | BindingFlags.Instance ,null,obj,args,pma,System.Globalization.CultureInfo.CreateSpecificCulture("zh-cn"),null); s = Convert.ToString(args[0]); textBox1.Text = s;
调用的时候也要写ref,你写的程序我看不太好。。
public class A { public void AMethod(ref int param) { param = 10; } } private void Form1_Load(object sender, System.EventArgs e) { A a = new A(); int param = 0; object[] theParams = new object[]{param}; typeof(A).InvokeMembe( "AMethod", System.Reflection.BindingFlags.Instance| System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod, null, a, theParams); param = (int)theParams[0]; }
Type t = Type.GetTypeFromProgID("SecurityToolkit.KeyManager");
object obj = Activator.CreateInstance(t);
object[] args = new object[]{s};
ParameterModifier m = new ParameterModifier(1);
m[0] = true;
ParameterModifier[] pma = {m};
object result = t.InvokeMember("GenerateKey",BindingFlags.InvokeMethod | BindingFlags.Instance ,null,obj,args,pma,System.Globalization.CultureInfo.CreateSpecificCulture("zh-cn"),null);
s = Convert.ToString(args[0]);
textBox1.Text = s;
{
public void AMethod(ref int param)
{
param = 10;
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
A a = new A();
int param = 0;
object[] theParams = new object[]{param};
typeof(A).InvokeMembe(
"AMethod",
System.Reflection.BindingFlags.Instance|
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.InvokeMethod,
null,
a,
theParams);
param = (int)theParams[0];
}