delphi编写spi程序中回调函数无法使用的问题(100分)

  • 主题发起人 主题发起人 lussy
  • 开始时间 开始时间
L

lussy

Unregistered / Unconfirmed
GUEST, unregistred user!
本人最近在写一个spi的过滤程序,出于对delphi的喜爱,我试着用delphi来实现,wspstartup已经转化成功,目前在转化wsprecv时遇到了一些问题,请各位大虾救命!

以下是部分的源程序,请各位指教,万分感谢!!!
TWSAOVERLAPPED_COMPLETION_ROUTINE=procedure(dwError:dword;cbTransferred:dword;lpOverlapped:PWSAOVERLAPPED;dwFlags:dword);stdcall;
TWSPRECV=function(s:Tsocket;var lpBuffers:Twsabuf;dwBufferCount:dword;var lpNumberOfBytesRecvd:dword;var lpFlags:dword;lpOverlapped:PWSAOVERLAPPED;lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE;lpThreadId:PWSATHREADID;var lpErrno:integer):integer;pascal;

procedure COMPLETION_ROUTINE(dwError:dword;cbTransferred:dword;lpOverlapped:PWSAOVERLAPPED;dwFlags:dword);stdcall;
begin
end;

function WSPRECV(s:Tsocket;var lpBuffers:Twsabuf;dwBufferCount:dword;var lpNumberOfBytesRecvd:dword;var lpFlags:dword;lpOverlapped:PWSAOVERLAPPED;lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE;lpThreadId:PWSATHREADID;var lpErrno:integer):integer;pascal;
begin
issetcompletionroutine:=false;
if assigned(lpOverlapped) then
begin
if assigned(lpCompletionRoutine) then
begin
issetcompletionroutine:=true;
lpCompletionRoutine:=COMPLETION_ROUTINE;
//该行代码加
//上后回调函数出错,哪位知道错在什么地方?
end;
end;
iret:=TWSPRECV(NextProcTable.LPWSPRecv)(s,lpBuffers,dwBufferCount,lpNumberOfBytesRecvd,lpFlags,lpOverlapped,lpCompletionRoutine,lpThreadId,lpErrno);
if (iret=socket_error) or (issetcompletionroutine=true) then
begin
result:=iret;
exit;
end;
result:=iret;
end;

VC函数原型为:
typedef
void
(CALLBACK * LPWSAOVERLAPPED_COMPLETION_ROUTINE)(
DWORD dwError,
DWORD cbTransferred,
LPWSAOVERLAPPED lpOverlapped,
DWORD dwFlags
);
typedef
int
(WSPAPI * LPWSPRECV)(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesRecvd,
LPDWORD lpFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
LPWSATHREADID lpThreadId,
LPINT lpErrno
);
 
后退
顶部