在C++中回调函数的原型是这样的
int WINAPI DJH323_SetCallEventHandler( DWORD dwEventMask, long (WINAPI * hdlr)(DWORD dwEvent, int iChID));
long WINAPI IPCallBackProc(DWORD dwEvent, int ch)
{
......
}
调用时: DJH323_SetCallEventHandler(H323_EV_ALL, IPCallBackProc);
我在delphi下这么定义:
type TIPCallBackProc= function(dwEvent: DWORD; iChID: Integer ):Integer;stdcall ;
function DJH323_SetCallEventHandler( dwEventMask: DWORD; IPCallBackProc: TIPCallBackProc):Integer; stdcall; far external 'djH323.dll';
函数实体
function IPCallBackProc( dwEvent: DWORD; IPch:Integer ):Integer;stdcall ;
begin
end;
调用时: DJH323_SetCallEventHandler(H323_EV_ALL, @IPCallBackProc);
可不知道为什么总是出错,好象是堆栈不一致,提示信息:
Debug Error!
Program : D:\....\project1.exe
Module:
file: i386\chkesp.c
line: 42The value of esp was not properly save across a function call. this is usually of calling a function declared with one calling convention with a function pointer declared with a different calling convention.高手们看看我的定义究竟哪里错了,急,在线等
int WINAPI DJH323_SetCallEventHandler( DWORD dwEventMask, long (WINAPI * hdlr)(DWORD dwEvent, int iChID));
long WINAPI IPCallBackProc(DWORD dwEvent, int ch)
{
......
}
调用时: DJH323_SetCallEventHandler(H323_EV_ALL, IPCallBackProc);
我在delphi下这么定义:
type TIPCallBackProc= function(dwEvent: DWORD; iChID: Integer ):Integer;stdcall ;
function DJH323_SetCallEventHandler( dwEventMask: DWORD; IPCallBackProc: TIPCallBackProc):Integer; stdcall; far external 'djH323.dll';
函数实体
function IPCallBackProc( dwEvent: DWORD; IPch:Integer ):Integer;stdcall ;
begin
end;
调用时: DJH323_SetCallEventHandler(H323_EV_ALL, @IPCallBackProc);
可不知道为什么总是出错,好象是堆栈不一致,提示信息:
Debug Error!
Program : D:\....\project1.exe
Module:
file: i386\chkesp.c
line: 42The value of esp was not properly save across a function call. this is usually of calling a function declared with one calling convention with a function pointer declared with a different calling convention.高手们看看我的定义究竟哪里错了,急,在线等
function DJH323_SetCallEventHandler( dwEventMask: DWORD; IPCallBackProc: TIPCallBackProc):Integer; stdcall; far external 'djH323.dll';
修改为:
function DJH323_SetCallEventHandler( dwEventMask: DWORD; IPCallBackProc: TIPCallBackProc):Integer; external 'djH323.dll';
to nxfbccu:
可是C语言下是没问题的,而类型应该也没问题呀,你看哪个地方类型不一致呢
不行,我就没有改过 Register了,因为好象看到过,如果类里的还是调用需要用Register
别的几个都试过了,还是不行
去掉Stdcall,出错
raised exception class EAccessViolation with message 'Access violation at address 00403A10' in module project1.exe
Module:
file: i386\chkesp.c
line: 42
这个错误信息比较奇怪,怎么会是C的文件啊?
应该是没问题的,一般用cdecl;如:
function DJH323_SetCallEventHandler( dwEventMask: DWORD; IPCallBackProc: TIPCallBackProc):Integer; CDECL; external 'djH323.dll';
好像是说调用堆栈被破坏,查MSDN上是这么说的。CDECL也试过了,出的错误是一样的,惨了
会不会使这个DLL中的函数跟Delphi不兼容呀,因为这个dll是一个硬件的驱动程序,肯定是用纯C开发的,在VC下没有问题
在我的机器上:
首先要 type TIPCallBackProc= function(dwEvent: DWORD; iChID: Integer ): LongInt; stdcall ;
第二 function DJH323_SetCallEventHandler( dwEventMask: DWORD; IPCallBackProc: TIPCallBackProc):Integer; cdecl; far external 'djH323.dll';