title: Calling functions accross classes causes Run-Time Check Failure #0 - The value of ESP was not properly saved
body: <p>I have a function that calls another function, which causes the following run-time check failure upon return to the calling function:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>The GridCtrl class:</p>
  
  <pre><code>class CNJAGridCtrl : public CWnd
  </code></pre>
  
  <p>The calling function code:</p>
  
  <pre><code>LRESULT CNJAGridCtrl::OnUpdateCell(WPARAM wParam, LPARAM lParam)
  {
      if (!(BOOL)wParam)
      {
          return true;
      }
      if (!m_bAllowUpdate)
      {
          return true;
      }
  
      NJACELLINFO *pDisp = (NJACELLINFO*)lParam;
      NJACELLINFO sDisp;
      sDisp.m_bFormatOnly = TRUE;
      sDisp.m_iColumn = pDisp-&gt;m_iColumn;
      sDisp.m_lLine = pDisp-&gt;m_lLine;
      GetDimensions(&amp;sDisp);
  
      sDisp.m_csText = pDisp-&gt;m_csText;
      BeginWaitCursor();
      UpdateCell(m_ctlLine.IsCurrentAddLine(), pDisp);//Function call with issue
      m_ctlSheet.InvalidateLine(sDisp.m_lLine, sDisp.m_lLine);
      EndWaitCursor();
  
      return true;
  }
  </code></pre>
  
  <p>The called function class:</p>
  
  <pre><code>class CGridProdReport : public CNJAGridCtrl  
  </code></pre>
  
  <p>and code:</p>
  
  <pre><code>void CGridProdReport::UpdateCell(BOOL bAdd,NJACELLINFO sDisp)
  {
  //Crashes even without any code
  }
  </code></pre>
  
  <p>I have no idea why this is happening. The compiler is set to use __cdecl across the board.</p>