【发布时间】:2010-05-12 00:08:16
【问题描述】:
我一直在尝试运行 stockbotprogramming http://www.stockbotprogramming.com/sharpcibtutorial1.php 教程中提供的示例项目,但每次运行应用程序时都会收到 COMException。
我正在运行 TWS 客户端,并且 API 提供的示例 VB 项目能够正常连接,但是当我尝试使用教程提供的 C# 示例时,出现以下异常:
未处理的类型异常 'System.Runtime.InteropServices.COMException' 发生在 System.Windows.Forms.dll 中
当我尝试添加 TWS ActiveX 控件时发生异常:
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);
}
}
}
最初的项目可能是用 Visual Studio 2005 完成的,但我有 Visual Studio 2008,它会自动转换项目(我一直在读到那里有一些问题)。有谁知道可能导致此异常的原因是什么?关于如何解决它的任何想法?
【问题讨论】:
标签: c# exception com controls activex