调用一个dll,是通过回调函数返回信息的。对方给的是用delphi调用,没有问题。现在在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
编译通过,运行时不进入回调函数,而且在调用函数那句不出错,在函数}返回时才报错。
从网上查这个错误是因为类型不匹配,不过没发现有不匹配的。delphi中的声明
type TSearchCallBackEx = function (buf:PSearchResponse; bufsize:integer;UserData:Pointer):boolean;stdcall;function PQNVR_GetFileList(LoginID:Integer;aDate: TDateTime; FileType: byte;
CHID: Integer; SearchCallBackEx: TSearchCallBackEx;
UserData: Pointer):boolean;stdcall;external 'PQNVR_Play.dll';
delphi中的定义
function SearchCB(buf:PSearchResponse; bufsize:integer;UserData:Pointer):boolean;stdcall;
var
Res:TSearchResponse;
begin
if buf<>nil then
begin
Move(buf^,Res,sizeof(Res));
Form1.ListBox11.Items.Add(Res.afile);
end
else
application.MessageBox('find file end','');
end;procedure TForm1.Button41Click(Sender: TObject);
var
yy,mm,dd:word;
begin
Listbox11.Items.Clear ;
//yy:=strtoint(copy(ComboBox26.Text,1,4));
//mm:=strtoint(copy(ComboBox26.Text ,6,2));
//dd:=strtoint(copy(ComboBox26.Text ,9,2));
yy:=2012;mm:=7;dd:=2;
PQNVR_GetFileList(LoginId, EncodeDate(yy,mm,dd),255,strtoint(Edit34.Text ),SearchCB,self);end;VC中的声明
typedef bool (WINAPI *TSearchCallBackEx)(TSearchResponse* buf,int bufsize,LPVOID UserData);
typedef int (WINAPI *PKNVRGetFileList)(int LoginID,CTime aDate,byte FileType,int CHID,TSearchCallBackEx SearchCallBackEx,LPVOID UserData);VC中的定义
bool WINAPI SearchCB(TSearchResponse* buf,int bufsize,LPVOID UserData)
{
/*CString filename,filetime;
if (buf!=NULL)
{
filename=buf->afile;
byte c=buf->head;
int index=filename.Find("192.168.1.160/0",0);
filetime=filename.Mid(index+17,6);
CTime t_user(2000,1,1,8,58,00);
CTime t_file(2000,1,1,atoi(filetime.Mid(0,2)),atoi(filetime.Mid(2,2)),atoi(filetime.Mid(4,2)));
if(((t_user-t_file)>0)&&((t_user-t_file)<3600))
{
return true;
}
//Form1.ListBox11.Items.Add(Res.afile);
}*/
return true;
}
void CMFCPKDlg::OnButton2()
{
// TODO: Add your control notification handler code here
char pBuf[MAX_PATH];
GetSystemDirectory(pBuf,MAX_PATH);
strcat(pBuf,"\\PQNVR_Play.dll");
DLLInst=LoadLibrary(pBuf); //获取系统文件夹下的dll
PKNVRGetFileList NVRGetFileList=NULL;
NVRGetFileList=(PKNVRGetFileList)GetProcAddress(DLLInst,"PQNVR_GetFileList");
CTime t_user(2012,3,2);
LPVOID p;
NVRGetFileList(NLoginID, t_user,0,0,SearchCB,this);
//ss(userid,t_user,0,0,SearchCB,p);
//test1(test,3);
}亟待解答,谢谢
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
编译通过,运行时不进入回调函数,而且在调用函数那句不出错,在函数}返回时才报错。
从网上查这个错误是因为类型不匹配,不过没发现有不匹配的。delphi中的声明
type TSearchCallBackEx = function (buf:PSearchResponse; bufsize:integer;UserData:Pointer):boolean;stdcall;function PQNVR_GetFileList(LoginID:Integer;aDate: TDateTime; FileType: byte;
CHID: Integer; SearchCallBackEx: TSearchCallBackEx;
UserData: Pointer):boolean;stdcall;external 'PQNVR_Play.dll';
delphi中的定义
function SearchCB(buf:PSearchResponse; bufsize:integer;UserData:Pointer):boolean;stdcall;
var
Res:TSearchResponse;
begin
if buf<>nil then
begin
Move(buf^,Res,sizeof(Res));
Form1.ListBox11.Items.Add(Res.afile);
end
else
application.MessageBox('find file end','');
end;procedure TForm1.Button41Click(Sender: TObject);
var
yy,mm,dd:word;
begin
Listbox11.Items.Clear ;
//yy:=strtoint(copy(ComboBox26.Text,1,4));
//mm:=strtoint(copy(ComboBox26.Text ,6,2));
//dd:=strtoint(copy(ComboBox26.Text ,9,2));
yy:=2012;mm:=7;dd:=2;
PQNVR_GetFileList(LoginId, EncodeDate(yy,mm,dd),255,strtoint(Edit34.Text ),SearchCB,self);end;VC中的声明
typedef bool (WINAPI *TSearchCallBackEx)(TSearchResponse* buf,int bufsize,LPVOID UserData);
typedef int (WINAPI *PKNVRGetFileList)(int LoginID,CTime aDate,byte FileType,int CHID,TSearchCallBackEx SearchCallBackEx,LPVOID UserData);VC中的定义
bool WINAPI SearchCB(TSearchResponse* buf,int bufsize,LPVOID UserData)
{
/*CString filename,filetime;
if (buf!=NULL)
{
filename=buf->afile;
byte c=buf->head;
int index=filename.Find("192.168.1.160/0",0);
filetime=filename.Mid(index+17,6);
CTime t_user(2000,1,1,8,58,00);
CTime t_file(2000,1,1,atoi(filetime.Mid(0,2)),atoi(filetime.Mid(2,2)),atoi(filetime.Mid(4,2)));
if(((t_user-t_file)>0)&&((t_user-t_file)<3600))
{
return true;
}
//Form1.ListBox11.Items.Add(Res.afile);
}*/
return true;
}
void CMFCPKDlg::OnButton2()
{
// TODO: Add your control notification handler code here
char pBuf[MAX_PATH];
GetSystemDirectory(pBuf,MAX_PATH);
strcat(pBuf,"\\PQNVR_Play.dll");
DLLInst=LoadLibrary(pBuf); //获取系统文件夹下的dll
PKNVRGetFileList NVRGetFileList=NULL;
NVRGetFileList=(PKNVRGetFileList)GetProcAddress(DLLInst,"PQNVR_GetFileList");
CTime t_user(2012,3,2);
LPVOID p;
NVRGetFileList(NLoginID, t_user,0,0,SearchCB,this);
//ss(userid,t_user,0,0,SearchCB,p);
//test1(test,3);
}亟待解答,谢谢
解决方案 »
- 关于CEdit类指针问题
- 关于网络编程 的一些名词解释?
- 会MFC的都进来看一下,RMB+100分回报
- 求救!AfxBeginThread创建辅助线程发生错误!!!
- Debug与Release 版的不同 ????(急!!!!!!!!!1)
- VC6 MSDN缺了几个帮助文件,哪位仁兄有的,可否发给在下一份,感激涕零!
- 请帮忙看看PreTranslateMessage中处理WM_WTSSESSION_CHANGE出错。。
- 什么是VXD?
- TinyXML报错:error C3861: '_snprintf_s': identifier not found?
- 获取应用程序安装目录(通常是C:\Program Files)的方法是什么?
- httpsendrequest超时?
- 微软的程序员一天写3行代码?
其他的类型是否兼容没有研究过。
声明或定义在哪?
delphi中
type
TSearchResponse = record
head : Byte;
afile : Array[0..69] of char;
end;
PSearchResponse=^TSearchResponse;VC中typedef struct _TSearchResponse
{
byte head;
CString afile;
}TSearchResponse;
怀疑是CTime的错误,但不知道怎么改,也不确认