I have come across an exception that I have no idea about.
" Unhandled exception at 0x00a2ac1b in SampleSocketCli ent.exe: 0xC0000005: Access violation writing location 0x00000020."
Below is the snippet of relevant code. I started getting this error only after I added 'pComboLeg' & 'addAllLegs' in the tickPrice(). Can someone please help me out. I have googled alot but can't figure out what am I doing wrong. If you need more code than this then please ask.
" Unhandled exception at 0x00a2ac1b in SampleSocketCli ent.exe: 0xC0000005: Access violation writing location 0x00000020."
Below is the snippet of relevant code. I started getting this error only after I added 'pComboLeg' & 'addAllLegs' in the tickPrice(). Can someone please help me out. I have googled alot but can't figure out what am I doing wrong. If you need more code than this then please ask.
Code:
[C.h file]
struct ComboLeg
{
ComboLeg()
:
conId(0),
ratio(0),
openClose(0),
shortSaleSlot(0)
{
}
long conId;
long ratio;
CString action;
CString exchange;
long openClose;
long shortSaleSlot; // 1 = clearing broker, 2 = third party
CString designatedLocation;
};
struct Contract
{
Contract()
: conId(0)
, strike(0)
, includeExpired(false)
, comboLegs(NULL)
{
}
long conId;
CString symbol;
CString secType;
CString expiry;
double strike;
CString right;
CString multiplier;
CString exchange;
CString primaryExchange;
CString currency;
CString localSymbol;
bool includeExpired;
CString comboLegsDescrip;
typedef std::vector<ComboLeg*> ComboLegList;
ComboLegList* comboLegs;
};
[C.h file end]
[D.h file]
typedef Contract::ComboLegList ComboLegList;
Contract& getContract() { return *m_contract; }
ComboLegList m_comboLegs;
std::auto_ptr<Contract> m_contract;
[D.h file end]
[D.cpp file]
m_contract(new Contract);
m_contract->comboLegs = &m_comboLegs;
[D.cpp file end]
[E.cpp file]
typedef long TickerId;
void tickPrice( TickerId tickerId, TickType tickType, double price, int canAutoExecute)
{
Contract& contract1 = m_dlgOrder->getContract();
ComboLeg* pComboLeg = new ComboLeg();
pComboLeg = NULL;
pComboLeg->conId = contract1.conId;
pComboLeg->ratio = 1;
pComboLeg->action = "BUY";
pComboLeg->exchange = "NYMEX";
pComboLeg->openClose = 0;
pComboLeg->shortSaleSlot = 0;
pComboLeg->designatedLocation = "";
ComboLegList* addAllLegs = new ComboLegList;
addAllLegs = NULL;
addAllLegs->push_back(pComboLeg);
contract1.secType = "BAG";
contract1.comboLegs = addAllLegs;
}
[E.cpp file end]
Comment