我一直在尝试运行该教程提供的样例项目,但每次运行应用程序时,我都会得到一个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 2005完成的,但是我有Visual 2008,它会自动转换该项目(我一直在阅读那里有一些问题)。有人知道是什么导致了这一异常吗?有什么解决办法吗?
发布于 2010-06-03 15:21:01
Form1_Load())axTws1.connect("", 7496, 0);
axTws1.reqMktData(0, "AMD", "STK", "", 0, "", "", "SMART", "ISLAND", "USD", "", 0);。
https://stackoverflow.com/questions/2815298
复制相似问题