在用反射的方式(后绑定)访问Com对象的时候,涉及这类问题。比如:
public class MyClass1
{
public int MyMethod( int i, ref long k)
{
k = 2;
return 0;
} public static void Main()
{
try
{
Type objType;
object objBinding; objType = typeof(MyClass1);
objBinding = Activator.CreateInstance(objType); Type[] paramTypes = new Type[] {Type.GetType("System.Int32"), Type.GetType("System.Int32&")};
MethodInfo m = objType.GetMethod("MyMethod",paramTypes);
object[] args = new object[2];
args[0] = 1;
args[1] = //-------写到这里就不知道怎么写了。
int res=m.Invoke(objBinding,args);
}
catch(TargetInvocationException ee)
{
Console.WriteLine("\terr:{0}",ee.Message);
}
} }
public class MyClass1
{
public int MyMethod( int i, ref long k)
{
k = 2;
return 0;
} public static void Main()
{
try
{
Type objType;
object objBinding; objType = typeof(MyClass1);
objBinding = Activator.CreateInstance(objType); Type[] paramTypes = new Type[] {Type.GetType("System.Int32"), Type.GetType("System.Int32&")};
MethodInfo m = objType.GetMethod("MyMethod",paramTypes);
object[] args = new object[2];
args[0] = 1;
args[1] = //-------写到这里就不知道怎么写了。
int res=m.Invoke(objBinding,args);
}
catch(TargetInvocationException ee)
{
Console.WriteLine("\terr:{0}",ee.Message);
}
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货