问题
Dear all trader and API Gurus,
Thank you in advance.
Background:
- Visual Studio 2010, C# Language, ActiveX OCX API as reference of project.
- Successively to use the method provided by API like reqAccountUpdate and use the event to receive information about account update.
Issue:
- 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
回答1:
//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.
来源:https://stackoverflow.com/questions/8477107/invalidcastexception-when-using-activex-in-c-sharp-project