InvalidCastException在C#项目中使用ActiveX时
亲爱的所有交易员和API大师,
先感谢您。
背景:
- Visual Studio 2010,C#语言,ActiveX OCX API作为项目的参考。
- 接下来使用API提供的方法,如reqAccountUpdate,并使用该事件接收有关帐户更新的信息。
问题:
- 现在我想要一个特定金融工具的数据,如外汇对:AUD.USD。
一个。 第1步:从TWSLibinheritance类IContract的接口我的代码在这里作为图片,构造函数特定于AUD.USD: 一只忙碌的猫http://sofzh.miximages.com/c%23/iyG7RLuSGxiEl.jpg
正如您所看到的,我已将私有对象_combolLegs更改为私有TWSLib.IComboLeg _comboLegs
湾 第2步:我还将IComboleg和IUpdateCompinheritance到ComboLeg和UpdateComp,并且我没有为它们分配任何值,因为它们与AUD.USD外汇交易无关。
C。 现在我创建一个合同实例并尝试分配所需的所有外汇合约信息并提交我的查询。 一只忙碌的猫http://sofzh.miximages.com/c%23/iXvgbSsp4MbYz.jpg
d。 这是一个运行时错误。 请查看图片: 忙碌的猫http://sofzh.miximages.com/c%23/ifFxdfnyvfKF9.jpg
似乎我创建的契约实例不能被api接受为正式的IContract实例。 任何.NET大师的想法?:)
再次提前感谢,
谦虚的学习者。
李文浩
编辑
关于IContract的细节,我得到了所有的信息
一只忙碌的猫http://sofzh.miximages.com/c%23/iAoY8rCvbC22z.jpg
//Try changing the way that you implement the Interface / Clase where you have // -- var auduse = new Contract(); //depending on boxing and unboxing from this point try to reverse it and do the following IContract iaudUse = new Contract(); //then you would use iaudUse. what ever method in the Interface that you are wanting to use.