CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2001
    Location
    jordan
    Posts
    63

    COM Interface - InvokeMember

    Hello
    I'm are trying to dynamically invoke a COM interface using the InvokeMember method but I'm having problems with the output parameters; they're not being returned. It works fine for input and return parameters, though.

    thank you

    awni

  2. #2
    Join Date
    Jul 2005
    Location
    Russian Federation. Moscow
    Posts
    152

    Lightbulb Re: COM Interface - InvokeMember

    Hi
    Do you mean the InvokeHelper()?
    Plz, describe the problem further. Paste some code here... I think we can help you
    Best regards, Alex Dronov
    Let the poster of the answers know when they helped you: Click "Rate this post!

  3. #3
    Join Date
    Jul 2001
    Location
    jordan
    Posts
    63

    Re: COM Interface - InvokeMember

    ok, this is for a friend who doesn't seem to be able to reach codeguru forums for some reason, so i'm going to mediate

    we're using c# to access a COM object, we have no idea what's inside it, we only have the interface. We manged to dynamically invoke a .NET assembly method (using the assembly, class and method names) and to get the output parameters, but whenever we try to invoke a method from a COM interface no output parameters are returned.

    here's some code

    ================================================
    string methodName = "MehtodName";



    Type t = Type.GetTypeFromProgID("COM.ProgId");

    object targetInstance = Activator.CreateInstance(t);



    //Prepare input and output parameters

    string param1 = "john";

    long param2 = 0;

    string param3 = "No Error";



    object[] parameters = new object[]{param1, param2, param3};



    //Set up the parameter modifiers.

    //Order: pdIn, pdOut, pdLcid, pdRetval, pdOptional, and pdHasDefault

    ParameterModifier inModifier = new ParameterModifier(1);

    ParameterModifier outModifier = new ParameterModifier(2);



    inModifier[0] = true;

    outModifier[1] = true;



    ParameterModifier[] modifiers = new ParameterModifier[3]{inModifier, outModifier, outModifier};



    object ret = null;



    try

    {

    //Invoke the target method

    ret = t.InvokeMember(

    methodName,

    BindingFlags.Instance |

    BindingFlags.Public |

    BindingFlags.InvokeMethod,

    null,

    targetInstance,

    parameters,

    modifiers,

    null,

    null);

    }

    catch(System.Reflection.TargetInvocationException ex)

    {

    Log(ex.InnerException.ToString());

    //exit the function

    }



    param2 = (long)parameters[1];

    param3 = (string)parameters[2];



    //do some work


    ================================================

    awni

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured