---
title: "Run-Time Check Failure #0 "
author: "eggbucket"
date: "2011-08-02T08:39:35Z"
tags: []
categories: ["编程语言"]
slug: "run-time-check-failure-0"
draft: false
lastmod: "2011-08-02T08:39:35Z"
id: 1137801
url: "https://eggbucket.iteye.com/blog/1137801"
---

关于Run-Time Check Failure #0  The value of ESP was not properly saved across a function call的问题!

 

 

    HINSTANCE hInst;  
    //加载动态链接库  
    hInst=LoadLibrary("chj800u.dll");

    /*  
    功能：打开usb评价器虚拟串口,并与设备建立连接  
    返回值：成功:返回相应的串口句柄 &gt;0  
        失败:返回 -1  
    \*/  
    typedef long (\_stdcall \*PJQ\_Open)();  
    /*  
    功能：与设备断开连接,并关闭usb评价器虚拟串口  
    返回值：成功:  0  
            失败:  -1  
    \*/  
    typedef long (\_\_stdcall \*PJQ\_Close)();

 

    //初始化评价器  
    PJQ\_Open Open=(PJQ\_Open)GetProcAddress(hInst,"PJQ\_Open");  
    //关闭评价器  
    PJQ\_Close Close=(PJQ\_Close)GetProcAddress(hInst,"PJQ\_Close");

 

    if(!Open)  
    {  
        MessageBox("获取函数地址失败！");  
        return;  
    }  
    //调用时出错!  
    long hand=Open();  
     
    EvaluateWait(hand,3);  
    Close();

    FreeLibrary(hInst);

 

 

在调用Open()方法时出错，原因是调用约定的问题：

解决方案:

在定义函数指针的时候加上 \_stdcall 表示标准调用约定. 默认是c调用约定.

   /*  
    功能：打开usb评价器虚拟串口,并与设备建立连接  
    返回值：成功:返回相应的串口句柄 &gt;0  
        失败:返回 -1  
    \*/  
    typedef long (\_stdcall \*PJQ\_Open)();