Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有交互式代理TWS API的System.WIndows.Forms.dll中的COMException_C#_Exception_Com_Controls_Activex - Fatal编程技术网

C# 带有交互式代理TWS API的System.WIndows.Forms.dll中的COMException

C# 带有交互式代理TWS API的System.WIndows.Forms.dll中的COMException,c#,exception,com,controls,activex,C#,Exception,Com,Controls,Activex,我一直在尝试运行stockbotprogramming教程中提供的示例项目,但每次运行应用程序时都会遇到一个COMException 我已经运行了TWS客户端,并且API提供的示例VB项目能够很好地连接,但是当我尝试使用教程提供的C#示例时,我得到了以下异常: 类型的未处理异常 'System.Runtime.InteropServices.COMException' 发生在System.Windows.Forms.dll中 尝试添加TWS ActiveX控件时发生异常: namespace C

我一直在尝试运行stockbotprogramming教程中提供的示例项目,但每次运行应用程序时都会遇到一个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);
        }
    }
}
命名空间CSharpTutorial1
{
公共部分类Form1:Form
{
私有AxTWSLib.AxTws tws;
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
tws=新的AxTWSLib.AxTws();
tws.BeginInit();
tws.Enabled=true;
tws位置=新系统图纸点(32664);
tws.Name=“tws”;
控件。添加(tws);//
  • 重要提示:确保使用可视化设计器将组件添加到IDE中。首先在工具箱中单击鼠标右键,单击“选择项”,单击“COM”选项卡,然后检查TWS控件。现在使用可视化IDE将此项拖动到窗体的表面。它必须在应用程序中可见。(不要在
    Form1\u Load()
    中创建它)

  • 执行以下操作…(不要使用127.0.0.1的IP地址,保留为空):


  • 最后(如果您使用的是64位Windows)以32位代码编译项目。转到configuration manager,然后创建一个新的配置文件“x86”,并将所有配置设置为x86
  • 最后!你是为IB工作还是什么?无论如何,谢谢你的帮助!
    axTws1.connect("", 7496, 0);
    axTws1.reqMktData(0, "AMD", "STK", "", 0, "", "", "SMART", "ISLAND", "USD", "", 0);