问题描述
我正在尝试使用Haru PDF库(http://libharu.sourceforge.net/index.html)制作一个小程序。我将其与我的项目静态链接,并具有一些基本的源代码来测试该库是否成功运行。源代码如下。
#include <iostream>
#include "hpdf.h"
void ErrorHandler(HPDF_STATUS errorNo,HPDF_STATUS errorDetail,void* userData)
{
std::cout << "ERROR" << std::endl;
}
int main()
{
HPDF_Doc pdf = HPDF_New(ErrorHandler,nullptr);
if (!pdf)
{
return 1;
}
HPDF_Free(pdf);
return 0;
}
编译程序时出现以下错误:
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.
通过一些研究,我发现这可能是由于不同的调用约定所致。但是,我对如何解决此问题一无所知。任何想法将不胜感激。
解决方法
我认为您应该尝试一些致电转化:
void WINAPI ErrorHandler(...)
void __stdcall ErrorHandler(...)
extern "C" {
void ErrorHandler(...)
}
或其他。