CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2001
    Posts
    2,455

    InvokeMethod and ParameterModifier

    I am using late binding to call a method in a COM object. There are three ref arguments in this function. I used ParameterModifier class to indicate this. The problem is that I am expecting the third argument to get a value but it get nothing. The function does succeed.

    The method signature according to the documentation:
    Code:
    public virtual int Create(ref object XMLSource, ref bool ModifyIfExists, ref string CptNumGenerated)
    The method where I call this function.
    Code:
          public int AddHoursEntry(string xml)
            {
                int result = 0;
                if (IsConnectedToDatabase)
                {
                    object hoursEntry = this.InterfaceType.InvokeMember("HoursEntry", BindingFlags.GetProperty, null, this.MaestroObject, null);
                    if (hoursEntry != null)
                    {
                        string cpt = "0";
                        bool modify = false;
    
                        object[] args = {xml, modify, cpt};
    
                        ParameterModifier p = new ParameterModifier(3);
                        p[0] = true;
                        p[1] = true;
                        p[2] = true;
    
                        ParameterModifier[] mods = { p };
    
                        result = (int)hoursEntry.GetType().InvokeMember("Create", 
                            BindingFlags.InvokeMethod,
                            null, 
                            hoursEntry, 
                            args,
                            mods,
                            null,
                            null);
    
                        if (result == 0)
                            result = Convert.ToInt32(cpt); // Expecting the cpt value to be > 0                    
                        else
                        {
                            object errorObj = this.interfaceType.InvokeMember("GetErrors", BindingFlags.InvokeMethod, null, this.MaestroObject, null);
                            if (errorObj != null)
                            {
                                this.LastError = (string)errorObj.GetType().InvokeMember("XML", BindingFlags.GetProperty, null, errorObj, null);
                            }
                            else
                                this.LastError = "Error unknown!";
                        }
                    }
                }
                return result;
            }
    Can anyone see anything I am doing wrong?

    Mike B
    Last edited by MikeB; July 30th, 2009 at 02:22 PM.

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