Help needed with run time error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Help needed with run time error

  1. #1
    Join Date
    Mar 2010
    Posts
    17

    Help needed with run time error

    I get the following error when I run the code.

    "Run-Time Check Failure #0 - The value of ESP was not properly saved
    across a function call. This is usually a result of calling a function
    declared with one calling convention with a function pointer declared
    with a different calling convention."

    Unable to understand what is causing this. Have given a snippet of the code that I think is relevant. Hope you can help me

    Code:
    [.cpp file]
    void CClient2Dlg::OnReqMktData()
    {
    	m_pClient->reqMktData( m_dlgOrder->m_id, m_dlgOrder->getContract(),
    		m_dlgOrder->m_genericTicks, m_dlgOrder->m_snapshotMktData);
    	
    	m_pClient->reqMktData2( m_dlgOrder->m_id, m_dlgOrder->getContract2(), 
    		m_dlgOrder->m_genericTicks, m_dlgOrder->m_snapshotMktData);
    }
    [file end]
    
    [.h file]
    void EClientSocketBase::reqMktData(TickerId tickerId, const Contract& contract, const IBString& genericTicks, bool snapshot)
    {
    	std::ostringstream msg;
            
            (more code)
    
            bufferedSend( msg.str());
    }
    
    void EClientSocketBase::reqMktData(TickerId tickerId, const Contract2& contract2, const IBString& genericTicks, bool snapshot)
    {
    	std::ostringstream msg2;
            
            (more code)
    
            bufferedSend( msg2.str());
    }
    [file end]
    
    [.cpp file]
    #include "StdAfx.h"
    #include "EClientSocket.h"
    
    class EClientSocket::MySocket : public CAsyncSocket
    {
    public:
    	MySocket( EClientSocket *pClient);
    	void OnConnect( int i);
    	void OnReceive( int i);
    	void OnSend( int i);
    	void OnClose( int i);
    private:
    	EClientSocket *m_pClient;
    };
    [file end]

  2. #2
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Help needed with run time error

    That code doesn't help. The reason is that we have no idea what the value of those pointers are, whether they're valid, or pointing to valid data.

    Your problem is either due to you calling an external function, and you didn't declare it correctly (you used __stdcall and the function is __cdecl, or vice-versa), or you are accessing an invalid pointer and corrupting the ESP register.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Mar 2010
    Posts
    17

    Re: Help needed with run time error

    The thing is that if I use only 1 of them, i.e.

    m_pClient->reqMktData( m_dlgOrder->m_id, m_dlgOrder->getContract(),
    m_dlgOrder->m_genericTicks, m_dlgOrder->m_snapshotMktData);

    it works fine. It is only when I try to use another one, i.e.

    m_pClient->reqMktData2( m_dlgOrder->m_id, m_dlgOrder->getContract2(),
    m_dlgOrder->m_genericTicks, m_dlgOrder->m_snapshotMktData);

    that I get the error.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Help needed with run time error

    As Paul said, there are 2 possible reasons: either getContract2() is calling a function with a different calling convention, or something in corrupting the stack. The first would be probably easier to spot that the later.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Mar 2010
    Posts
    17

    Re: Help needed with run time error

    I modified the code a little so that the calling becomes more consistent. I removed reqMktData2. But I still end up getting the same error. It works when I keep either one of them, but not both. This is what I did.

    Code:
    [.cpp file]
    m_pClient->reqMktData( m_dlgOrder->m_id, m_dlgOrder->getContract(),
    		m_dlgOrder->m_genericTicks, m_dlgOrder->m_snapshotMktData);
    
    m_pClient->reqMktData( m_dlgOrder->m_id2, m_dlgOrder->getContract2(),
    		m_dlgOrder->m_genericTicks, m_dlgOrder->m_snapshotMktData);
    [file end]
    
    [.h file]
    void EClientSocketBase::reqMktData(TickerId tickerId, const Contract& contract, 
    								   const IBString& genericTicks, bool snapshot)
    {
            std::ostringstream msg;
            
            (more code)
    
            bufferedSend( msg.str());
    }
    
    void EClientSocketBase::reqMktData(TickerId tickerId, const Contract2& contract2, 
    								   const IBString& genericTicks, bool snapshot)
    {
            std::ostringstream msg;
            
            (more code)
    
            bufferedSend( msg.str());
    }
    [file end]
    
    [.h file]
    virtual void reqMktData( TickerId id, const Contract &contract,
    	   const IBString& genericTicks, bool snapshot) = 0;
    
    virtual void reqMktData( TickerId id, const Contract2 &contract2,
    	   const IBString& genericTicks, bool snapshot) = 0;
    [file end]
    
    [.h file]
    void reqMktData(TickerId id, const Contract &contract,
    		const IBString &genericTicks, bool snapshot);
    
    void reqMktData(TickerId id, const Contract2 &contract2,
    		const IBString &genericTicks, bool snapshot);
    [file end]

  6. #6
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Help needed with run time error

    Quote Originally Posted by pokopolo View Post
    I modified the code a little so that the calling becomes more consistent. I removed reqMktData2. But I still end up getting the same error. It works when I keep either one of them, but not both. This is what I did.
    Sorry, but again, your code does not help.

    First, things like this:
    Code:
    (more code)
    littered within your post creates more questions. We don't know what you're doing in the (more code), and could be a cause for the whole issue. Secondly, you are calling functions which we have no idea what they are doing (bufferedSend() for example).

    Secondly and most important, unless the program is a toy program, runtime problems cannot be solved by looking at pieces of code. To solve a runtime problem, the person trying to solve the problem must have something to run. We don't have your entire code, so unless you post everything, then it's up to you to solve the problem yourself.

    The reason for the error is again, those functions are declared with the wrong calling convention, or your program has corrupted the stack. There are no other reasons.

    Which functions have the wrong or incorrect calling conventions -- we don't know, you need to find out. If there is stack corruption, you need to debug your program to see if you are making illegal pointer accesses, passing non-NULL (but illegal) pointers, etc.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center