关于DLL中有回调函数的情况
hq007 2007-01-22 05:41:47
这个DLL是用VC实现的,我现在想用DELPHI来调用。
其中DLL中有一个函数的声明是这样的:
DLLEXPORT_API int __stdcall RegisterStreamDirectReadCallback(STREAM_DIRECT_READ_CALLBACK StreamDirectReadCallback,void *Context);
其中STREAM_DIRECT_READ_CALLBACK 是一个回调函数。在用VC写的例子中是这样调用这个函数的:
//声明函数指针
typedef int (*STREAM_DIRECT_READ_CALLBACK)(ULONG channelNumber,void *DataBuf,DWORD Length,int FrameType,void *context);
//声明一个相对应的函数
int __cdecl StreamDirectReadCallback(ULONG channelNumber,void *DataBuf,DWORD Length,int FrameType,void *context);
...........
//调用
RegisterStreamDirectReadCallback(::StreamDirectReadCallback,this);
也就是说DLL中没有定义StreamDirectReadCallback这个函数,而是在这个VC例子中自己定义的一个函数。
////////////////////////////////////////////
下面是本人用DELPHI调用这个函数的写法:
//回调函数类型声明
TYPE
STREAM_DIRECT_READ_CALLBACK=Function(channelNumber:longint;DataBuf:pointer;Length:DWORD;FrameType:integer;context:pointer):integer;stdcall;
function StreamDirectReadCallBack(channelNumber:longint;DataBuf:pointer;Length:DWORD;FrameType:integer;context:pointer):integer;stdcall;external 'DS40xxSDK.dll';
Function RegisterStreamDirectReadCallBack(StreamDirectReadCallBack:STREAM_DIRECT_READ_CALLBACK;context:pointer):integer;stdcall;external 'DS40xxSDK.dll';
................
//调用时是这样写的:
v:=RegisterStreamDirectReadCallBack(@StreamDirectReadCallBack,self);
...
编译时提示下面的错误:
“无法定位程序输入点RegisterStreamDirectReadCallBack于动态库DS40xxSDK.dll上” ,
首先,动态库是没有问题的,应为该动态库其他的函数我测试过都可以的。请问一下大家有没有遇到过这种情况,请帮帮忙,谢谢了。