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"

解决方案 »

  1.   

    因为你给result赋的值就是"NONE"
      

  2.   

    授人以鱼不如授人以渔,看这里
    http://blog.sina.com.cn/s/blog_49ae2a93010007qs.html
      

  3.   

    result = "NONE";
    因为这里赋值的就是“NONE”
    而斜面的方法调用并不能更改当前的result变量中的值。
    oType.InvokeMember()除非在方法参数中加上ref 或 out来标识传递引用,才可以更改这个result的值。
    例如:
    result = "NONE";
    ExecuteEx(ref result);
    这样的话,在ExecuteEx函数中更改result的值才会影响到外面定义的result变量。
      

  4.   

    ExecuteEx(ref result);在C#中提示错误
    为什么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#没多久还希望各位大师帮帮忙多多指教先谢过了
      

  5.   

            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";
                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参数。
      

  6.   


    这样写还是没有把我要的信息反馈回来啊并且result=param[2];这里提示错误
    我在使用时会给str_Renamed一个字符串例如:str_Renamed="a"
    之后在VB.net中直接用pm.ExecuteEx(str_Renamed, pml_error, result)这个代码就可以将返回的字符串返回到result里,而现在用C#  result的值一直都是"NONE"并没有返回我所要的字符串
      

  7.   

    可以把错误信息贴详细一点看看,即使得不到值,也不因该报错啊。
    ExecuteEx这个函数是哪儿来的?什么写的?
      

  8.   


        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"
    麻烦您了
      

  9.   


    result=param[2].ToString();
    ToString一下就OK了。
      

  10.   

    result还是"NONE"啊
    C#写这代码都可以发送字符串了怎么就接收不到返回的信息啊
      

  11.   


         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 });
            }
      

  12.   

    out 一下.你result 执行oType.InvokeMember完这个的时候.你没有给result 重新赋值
      

  13.   


    out result这里提示错误怎么办啊
      

  14.   

    如果不变的话说明你的result不是一个ref参数。
    你把这个函数法出来看看/?ExecuteEx
      

  15.   


    左面的是C#的右面的是vb.net的  vb.net执行完ExecuteEx
    之后result值就从"NONE"改变了  C#却没有  
      

  16.   

    VB中有一个Test方法(参数是ref的)Module Module1    Sub Main()
            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)是怎么定义的啊。
      

  17.   

      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";
                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 组件的引用传递参数时才需要这个。
      

  18.   

    非常感谢各位师傅
    尤其是haukwong师傅 谢谢了