问题是这样的:
我有一个动态链接库MYDLL.dll,在VB里调用成功,VC里调用不成功,VB代码如下:
Private Declare Function PT Lib "MYDLL.DLL" (ByVal a#) As Double
Public Function PT(ByVal p As Double)
t = StmPT(p)
End Function
因为没有lib文件,VC里只能采取显示调用,但我没有调用成功,错误提示如下:
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.
testDlg.cpp代码如下:
HINSTANCE gLibMyDLL=NULL;
typedef double(*STMTP)(double a);
STMTP StmTP;
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
.
.
.
gLibMyDLL=LoadLibrary("MYDLL.DLL");
if(gLibMyDLL!=NULL)
{
MessageBox("装载MYDLL成功");
}
StmTP=(STMTP)GetProcAddress(gLibMyDLL,"StmTP");
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
double c;
c= StmTP(2.0);
CDialog::OnOK();
}
补充说明:为了避免我的调用方法有问题,我自编了一个类似的数学函数,做成dll,用同样的方法调用成功。
此处出现这个问题,实不知错在何处,望高手指点!
我有一个动态链接库MYDLL.dll,在VB里调用成功,VC里调用不成功,VB代码如下:
Private Declare Function PT Lib "MYDLL.DLL" (ByVal a#) As Double
Public Function PT(ByVal p As Double)
t = StmPT(p)
End Function
因为没有lib文件,VC里只能采取显示调用,但我没有调用成功,错误提示如下:
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.
testDlg.cpp代码如下:
HINSTANCE gLibMyDLL=NULL;
typedef double(*STMTP)(double a);
STMTP StmTP;
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
.
.
.
gLibMyDLL=LoadLibrary("MYDLL.DLL");
if(gLibMyDLL!=NULL)
{
MessageBox("装载MYDLL成功");
}
StmTP=(STMTP)GetProcAddress(gLibMyDLL,"StmTP");
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
double c;
c= StmTP(2.0);
CDialog::OnOK();
}
补充说明:为了避免我的调用方法有问题,我自编了一个类似的数学函数,做成dll,用同样的方法调用成功。
此处出现这个问题,实不知错在何处,望高手指点!
你怎么去找"StmTP"?应该如下
StmTP=(STMTP)GetProcAddress(gLibMyDLL,"TP");
Private Declare Function StmPT Lib "MYDLL.DLL" (ByVal a#) As DoubleVB里调用StmPT函数是对的,VC里调StmPT函数出错。请高手继续指点,3X!
typedef BOOL (WINAPI * StmTP)(double a);
StmTP pfnStmTP;hLibrary=LoadLibrary("MYDLL.DLL"); //加载DLL
if(hLibrary) //加载成功
{
pfnStmTP=(StmTP)GetProcAddress(hLibrary,"StmTP");
}