mercredi 19 août 2015

Reflection: Missing returnvalues

I need to use an existing COM Library. The Method "GetPosition" should return a value in the second argument ( x ) . This Methode is working; it returns the errorcode and sends the number correct. But the Problem is: It doesn't return the second argument ( x )! Some Idea?

  public class LibTest
  {
     static Type objType = Type.GetTypeFromProgID("myCOMLibrary");
     static object myObject = Activator.CreateInstance(objType);        

     static int GetPosition(int number, ref double x)
     {
        object[] oParms = new Object[] { number, x };
        int error = (int)objType.InvokeMember("GetPosition",
                       BindingFlags.InvokeMethod, null, myObject , oParms);

        // x = (double)oParms[1]; //Just a Test, the value is the same as before (12.0)
        return (error);

     }

   }

   public partial class Form1 : Form
   {
      double wert = 12.0; 
      int error = LibTest.GetPosition(1, ref wert);
      MessageBox.Show(wert.ToString()); // wert = 12.0
   }





Aucun commentaire:

Enregistrer un commentaire