COMException in System.WIndows.Forms.dll with Interactive Brokers TWS API

Posted by Lirik on Stack Overflow See other posts from Stack Overflow or by Lirik
Published on 2010-05-12T00:08:16Z Indexed on 2010/05/12 0:14 UTC
Read the original article Hit count: 445

Filed under:
|
|
|
|

Hi, I've been trying to run the sample project provided with the tutorial at stockbotprogramming http://www.stockbotprogramming.com/sharpcibtutorial1.php , but I keep getting a COMException every time I run the application.

I have the TWS Client running and the sample VB projects provided with the API are able to connect just fine, but when I try to use the C# sample provided by the tutorial then I get the following exception:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Windows.Forms.dll

Th exception happens when I try to add the TWS ActiveX control:

namespace CSharpTutorial1
{

    public partial class Form1 : Form
    {
        private AxTWSLib.AxTws tws;
        public Form1()
        {
            InitializeComponent();         
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            tws = new AxTWSLib.AxTws();
            tws.BeginInit();
            tws.Enabled = true;
            tws.Location = new System.Drawing.Point(32, 664);
            tws.Name = "tws";
            Controls.Add(tws); // <-- EXCEPTION HERE!
            tws.EndInit();
            tws.connect("127.0.0.1", 7496, 0);
            String msg = "Connected to TWS server version " + tws.serverVersion + "at " + tws.TwsConnectionTime;
            MessageBox.Show(msg);
        }
    }
}

Does anybody know what could be causing this exception? Any ideas on how to fix it?

© Stack Overflow or respective owner

Related posts about com

Related posts about exception