Run-Time Check Failure #0,The value of ESP was not properly saved 错误解决

调用DLL函数,出现错误

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.

错误原因:

你定义函数指针原型时出错。

其实你定义的没有错,但是编译器不认识而已,因为你调用的dll函数是一个远函数,而且是一个C函数,你得告诉编译器它是个c函数才行。那么你就可以在定义该函数的时候加上一句话,

FAR PASCAL 或者 __stdcall 这个就OK了。

具体做法:

比如说你要定义一个 返回类型为空,参数为空的函数指针:

typedef void (*LPFUN)(void);

这样确实跟我们dll里的函数匹配了,上面也说了,我们应该添上几个字,告诉编译器这个是一个远的C函数。

typedef void (WINAPI *LPFUN)(void);

typedef void (__stdcall *LPFUN)(void);

typedef void    (FAR PASCAL *LPFUN)    (void);

像上面这样定义就OK了,如果用的是VC++,那么直接用第一种定义就ok了。

注意,上面是使用 MFC (DLL)的做法。

如果是WIN32 DLL,得相应的去掉WINAPI ,__stdcall ,FAR PASCAL 这几个参数。因为WIN32 DLL 默认的入栈方式为 __cedcall方式,不是__stdcall方式。

具体的组合方式太多了,反正知道错误的原因是声明相应的函数未匹配就行了。



调用DLL里的函数 或 类成员函数 碰到此错误:

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.

 

函数定义的调用规则,和实际的调用规则不同。如 编译器默认的是__cdecl,而__stdcall 类型的函数却用了 __cdecl 的调用规则,由于编译时不会报错,结果出现了运行时异常。

所以把在函数定义中进行设置调用规则即可解决此问题。

如:  typedef void (__stdcall Foo)(int a);



很久没写代码,一天几行的代码:

typedef  int ( *PFUN)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
void CTestProcessMonitorDlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here

    //MessageBox(TEXT("Hello"), TEXT("Test"));

    //typedef void (*pfv) ();

    HMODULE hmod = ::LoadLibraryExW(TEXT("user32.dll"), NULL, 0);
    if (hmod != NULL)
    {
        PFUN pFun= (PFUN)GetProcAddress(hmod, "MessageBoxW");
        if (pFun != NULL)
        {
            pFun(m_hWnd, TEXT("Hello"), TEXT("Test"), MB_YESNO);
        }

       :FreeLibrary(hmod);
    }

   
                  
}

突然出现以下的错误:

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.



代码改为如下, 则问题没有了

typedef  int (WINAPI *PFUN)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
void CTestProcessMonitorDlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here

    //MessageBox(TEXT("Hello"), TEXT("Test"));

    //typedef void (*pfv) ();

    HMODULE hmod = ::LoadLibraryExW(TEXT("user32.dll"), NULL, 0);
    if (hmod != NULL)
    {
        PFUN pFun= (PFUN)GetProcAddress(hmod, "MessageBoxW");
        if (pFun != NULL)
        {
            pFun(m_hWnd, TEXT("Hello"), TEXT("Test"), MB_YESNO);
        }

         ::FreeLibrary(hmod);
    }
                      
}

// 调用约定出现问题,以前这样调用api也没有用上WINAPI , 现在突然就需要了,很是迷惑??? 盼知情者指点!




  • 11
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
Abstract: Current approaches for visual-inertial odometry (VIO) are able to attain highly accurate state estimation via nonlinear optimization. However, real-time optimization quickly becomes infeasible as the trajectory grows over time; this problem is further emphasized by the fact that inertial measurements come at high rate, hence leading to fast growth of the number of variables in the optimization. In this paper, we address this issue by preintegrating inertial measurements between selected keyframes into single relative motion constraints. Our first contribution is a preintegration theory that properly addresses the manifold structure of the rotation group. We formally discuss the generative measurement model as well as the nature of the rotation noise and derive the expression for the maximum a posteriori state estimator. Our theoretical development enables the computation of all necessary Jacobians for the optimization and a-posteriori bias correction in analytic form. The second contribution is to show that the preintegrated IMU model can be seamlessly integrated into a visual-inertial pipeline under the unifying framework of factor graphs. This enables the application of incremental-smoothing algorithms and the use of a structureless model for visual measurements, which avoids optimizing over the 3D points, further accelerating the computation. We perform an extensive evaluation of our monocular VIO pipeline on real and simulated datasets. The results confirm that our modelling effort leads to accurate state estimation in real-time, outperforming state-of-the-art approaches.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值