static object pm;
public static void pmstrat()
{
System.Type oType;
oType = System.Type.GetTypeFromProgID("Pmill.Document");
pm = System.Activator.CreateInstance(oType);
oType.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, pm, new object[] { true });
string returnValue;
int pml_error=0;
string result;
result = "NONE";
oType.InvokeMember("ExecuteEx", System.Reflection.BindingFlags.InvokeMethod, null, pm, new object[] { str_Renamed, pml_error, result });
}
这段代码result为什么总是"NONE"
public static void pmstrat()
{
System.Type oType;
oType = System.Type.GetTypeFromProgID("Pmill.Document");
pm = System.Activator.CreateInstance(oType);
oType.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, pm, new object[] { true });
string returnValue;
int pml_error=0;
string result;
result = "NONE";
oType.InvokeMember("ExecuteEx", System.Reflection.BindingFlags.InvokeMethod, null, pm, new object[] { str_Renamed, pml_error, result });
}
这段代码result为什么总是"NONE"
解决方案 »
- 类似于word里德查找功能
- C#如何避免连续按两次按钮
- 一个关于字符串搜索的问题
- 一个简单计算的问题!
- 回复帖子跳转到最后一页是怎么实现的?求求各位帮帮忙
- 哪位高人有用C#写的实现图象hextile编码的源程序啊,感谢!
- 怎么写一个windows服务和应用程序,让他们之间可以互相写读数据。
- 上传文件 高手请进
- 水晶报表的问题:一指定.rpt文件的数据源为项目中创建的数据集(添加的.xsd数据集文件)==》ado.net==>使用visual studio数据类就出现下
- C#与ASP.NET是如何共同编写B/S程序的?(我想入门)
- 如何弹消息框
- 求大神解决C# winform实现边滚动滚动条边加载图片?类似搜狗壁纸的?
http://blog.sina.com.cn/s/blog_49ae2a93010007qs.html
因为这里赋值的就是“NONE”
而斜面的方法调用并不能更改当前的result变量中的值。
oType.InvokeMember()除非在方法参数中加上ref 或 out来标识传递引用,才可以更改这个result的值。
例如:
result = "NONE";
ExecuteEx(ref result);
这样的话,在ExecuteEx函数中更改result的值才会影响到外面定义的result变量。
为什么oType.InvokeMember("Execute", System.Reflection.BindingFlags.InvokeMethod, null, pm, new object[] { str_Renamed, error_Renamed });这句发送字符串的命令没有错误
而oType.InvokeMember("ExecuteEx", System.Reflection.BindingFlags.InvokeMethod, null, pm, new object[] { str_Renamed, pml_error, result });返回信息的提示错误啊?学C#没多久还希望各位大师帮帮忙多多指教先谢过了
public static void pmstrat()
{
System.Type oType;
oType = System.Type.GetTypeFromProgID("Pmill.Document");
pm = System.Activator.CreateInstance(oType);
oType.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, pm, new object[] { true });
string returnValue;
int pml_error=0;
string result;
result = "NONE";
object[] param = new object[] { str_Renamed, pml_error, result };
oType.InvokeMember("ExecuteEx", System.Reflection.BindingFlags.InvokeMethod, null, pm, param);
result=param[2];
}
前提要求result对应的参数是一个ref参数或者out参数。
这样写还是没有把我要的信息反馈回来啊并且result=param[2];这里提示错误
我在使用时会给str_Renamed一个字符串例如:str_Renamed="a"
之后在VB.net中直接用pm.ExecuteEx(str_Renamed, pml_error, result)这个代码就可以将返回的字符串返回到result里,而现在用C# result的值一直都是"NONE"并没有返回我所要的字符串
ExecuteEx这个函数是哪儿来的?什么写的?
Dim pm As Object
Public Function pm_send_ex(ByRef str_Renamed As String) As String
pm = CreateObject("Pmill.Document")
pm.Visible = True
Dim pml_error As Integer
Dim result As String
result = "NONE"
pm.ExecuteEx(str_Renamed, pml_error, result)
End Function
这是vb.net中的代码我要把它用C#写出来可是result总是"NONE"
麻烦您了
result=param[2].ToString();
ToString一下就OK了。
C#写这代码都可以发送字符串了怎么就接收不到返回的信息啊
static object pm;
public static void pmstrat()
{
System.Type oType;
oType = System.Type.GetTypeFromProgID("Pmill.Document");
pm = System.Activator.CreateInstance(oType);
oType.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, pm, new object[] { true });
string returnValue;
int pml_error=0;
string result;
result = "NONE";
oType.InvokeMember("ExecuteEx", System.Reflection.BindingFlags.InvokeMethod, null, pm, new object[] { str_Renamed, pml_error,out result });
}
out result这里提示错误怎么办啊
你把这个函数法出来看看/?ExecuteEx
左面的是C#的右面的是vb.net的 vb.net执行完ExecuteEx
之后result值就从"NONE"改变了 C#却没有
Dim str As String
str = "aaaa"
Test(str)
Console.WriteLine(str)
End Sub Sub Test(ByRef str As String)
str = "bbbb"
End SubEnd Module static void Main(string[] args)
{
Assembly ass = Assembly.LoadFile(System.Environment.CurrentDirectory + "/TestVB.exe");
Type type = ass.GetType("TestVB.Module1");
object[] param = new object[] { "" };
type.InvokeMember("Test", BindingFlags.InvokeMethod, null, null, param);
Console.WriteLine(param[0]);//程序输出:bbbb
}所以这个方式是没错的,看看这个函数(ExecuteEx)是怎么定义的啊。
public static void pmstrat()
{
System.Type oType;
oType = System.Type.GetTypeFromProgID("Pmill.Document");
pm = System.Activator.CreateInstance(oType);
oType.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, pm, new object[] { true });
string returnValue;
int pml_error=0;
string result;
result = "NONE";
object[] param = new object[] { str_Renamed, pml_error, result };
ParameterModifier p = new ParameterModifier(3);
p[2] = true;
ParameterModifier[] mods = { p };
oType.InvokeMember("ExecuteEx", System.Reflection.BindingFlags.InvokeMethod, null, pm, param, mods, null, null);
result=param[2];
}
这样试试看?这就是#3版主发的那个,访问 COM 组件的引用传递参数时才需要这个。
尤其是haukwong师傅 谢谢了