How to call methods in a Windows Form Application Host from InfoPath? - InfoPath Dev
in

InfoPath Dev

How to call methods in a Windows Form Application Host from InfoPath?

Last post 06-25-2009 04:55 AM by BeniGemperle. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-19-2009 12:36 AM

    How to call methods in a Windows Form Application Host from InfoPath?

    Hi,
     
    I’m creating a Windows Form Application that hosts an InfoPath Form Control. The InfoPath Form has to be able to call methods in the host application. This should work by passing an object to the InfoPath FormControl Host Property. I don’t get this to work. I always get an InvalidCastException without any details.
     
    What are the requirements to object set in the Host Property?
    Can somebody please provide me a working example?
     
    NotifyHost() works, but I need to call methods that give back data.
     
    Thanks
    Benjamin
  • 06-25-2009 04:55 AM In reply to

    Re: How to call methods in a Windows Form Application Host from InfoPath?

    I found out this works.

    In an assembly HostAPI is this:

    [ComVisible(true)]
    [Serializable()]
    public class HostAPI{
          public void Save()
          {
                MessageBox.Show("HostAPI - Save()");
          }
    }

    Code in Host Form:
    formControl1.Host = new HostAPI();

     

    So, code in the assembly HostAPI can be executed from the InfoPath Form Code. Is this the correct way?

    Isn't it possible to make the HostAPI abstract and set this to the Host property?

    Or haw can I make HostAPI virtual?

     

     

    This results in the reported InvalidCastException:

     

    HostAPI assembly:


    public abstract class HostAPI{
          public abstract void Save();
    }


    Code in Host Form:


    public class HostAPICommands : HostAPI
    {
          public override void Save()
          {
                MessageBox.Show("HostAPICommands - Save()");
          }
    }

     

    HostAPICommands HostCommands = new HostAPICommands();
    HostAPI HostObject = (HostAPI)HostCommands;

    formControl1.Host = HostObject; // InvalidCastException occurs here

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.