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