在 C# 项目中使用 ActiveX 时 InvalidCastException

发布于 2024-12-20 17:21:52 字数 1256 浏览 0 评论 0原文

亲爱的所有交易者和 API 专家,

先谢谢你们。

背景:

  1. Visual Studio 2010、C#语言、ActiveX OCX API作为项目参考。
  2. 依次使用reqAccountUpdate等API提供的方法,利用事件接收账户更新信息。

问题:

  1. 现在我需要有关一种特定金融工具的数据,例如外汇对: AUD.USD 。

一个。步骤1:从TWSLib继承IContract类的接口,我的代码在这里为图片,构造函数是针对AUD.USD的: 一只忙碌的猫 http://i.minus.com/iyG7RLuSGxiEl.jpg

正如你所看到的我已将私有对象 _combolLegs 更改为私有 TWSLib.IComboLeg _comboLegs

b。步骤 2:我还将 IComboleg 和 IUpdateComp 继承到 ComboLeg 和 UpdateComp,并且我没有为它们分配任何值,因为它们不相关 到 AUD.USD 外汇交易。

c.现在,我创建一个合约实例,并尝试分配外汇合约所需的所有信息并提交我的查询。 一只忙碌的猫 http://i.minus.com/iXvgbSsp4MbYz.jpg

这是一个运行时错误。请检查这里的图片: 一只忙碌的猫 http://i.minus.com/ifFxdfnyvfKF9.jpg

我创建的合约实例无法被 api 接受为正式的 IContract 实例。 .NET 专家有什么想法吗?:)

再次感谢

谦虚的学习者。

文浩

编辑

关于IContract所有我到目前为止得到的细节

一只忙碌的猫http:// /i.minus.com/iAoY8rCvbC22z.jpg

Dear all trader and API Gurus,

Thank you in advance.

Background:

  1. Visual Studio 2010, C# Language, ActiveX OCX API as reference of project.
  2. Successively to use the method provided by API like reqAccountUpdate and use the event to receive information about account update.

Issue:

  1. Now I would like to require data about one specific financial instrument like a forex pair: AUD.USD .

a. Step 1: Inherit the interface of class IContract from TWSLib my Code is here as a picture and the constructor is specific for AUD.USD:
a busy cat http://i.minus.com/iyG7RLuSGxiEl.jpg

As you can see that I have change the private object _combolLegs to private TWSLib.IComboLeg _comboLegs

b. Step 2: I also inherit the IComboleg and IUpdateComp to ComboLeg and UpdateComp and I do not assign any value to them since they are not related
to the the AUD.USD forex trading.

c. Now I create a instance of contract and try to assign all information forex contract required for and submit my query.
a busy cat http://i.minus.com/iXvgbSsp4MbYz.jpg

d. it is a runtime error. Please check the picture here:
a busy cat http://i.minus.com/ifFxdfnyvfKF9.jpg

It seems like the contract instance I created could not be accepted by the api as formal IContract instance. Any idea from any .NET gurus?:)

Thanks lot in advance again,

Humble learner.

Wenhao

Edit

about the detail of IContract all I got sofar

a busy cat http://i.minus.com/iAoY8rCvbC22z.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哥,最终变帅啦 2024-12-27 17:21:52
//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.
//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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文