(高分求解)请问如何建立callback函数

gum 2000-08-06 12:40:00
请问如何建立callback函数

在第三方控件(采用visual c++5)有一函数功能如下:
FP_SetupUIlink is used to set up the link between a device
and the User Interface (UI), via an argument of type
FP_UI_LINK_PT which contains callback functions and device
parameters.

$$$.lib 声明文件:$$$.h

$$$.h

DLL_INTERFACE
FP_RETCODE FP_setupUIlink(
IN FP_HANDLE fpContext, /* context */
IN FP_UI_LINK_PT fpUIlink, /* UI link information */
IN void *pParam); /* A pointer to a user data
... to be passed to callback functions
or NULL */
/* This function sets up the link with the UI to provide feedback and
gets the user actions
...

typedef FP_ACTION (*FP_GET_ACTION) (IN FP_STATUS_PT, void *);
/* The application receives the status, acts upon the status, handles the UI,
and returns a user action */
...

typedef struct /* application params */
{
FP_GET_ACTION getAction; /* callback for user action */
...
}
FP_UI_LINK, *FP_UI_LINK_PT;
...

typedef enum /* user actions provided by the application to the SDK */
{
FP_ID_CANCEL, /* cancel */
FP_ID_CONTINUE, /* go on */
}
FP_ACTION, *FP_ACTION_PT;
...

typedef enum /* status codes provided to the application by SDK */
{
FP_WAITING, /* now waiting for device */
...
}
FP_STATUS_CODE;


以上为结构等的声明。
************************************************************

Unit1.cpp

void __fastcall TForm1::Button1Click(TObject *Sender)
{
1) typedef FP_RETCODE _stdcall(*SetupUIlink)(FP_HANDLE,FP_UI_LINK_PT,void *);
2) HINSTANCE hdl; //DLLa模块的句柄
3) FP_RETCODE rc;
4) hdl = LoadLibrary("$$$.dll");
5) if(hdl)
6) { //loadlibrary
...
7) SetupUIlink lpSetupUIlink;
8) FP_UI_LINK_PT FpUILink; //UI link information
9) FpUILink=new FT_UI_LINK; //UI link information
10) FP_GET_ACTION GetRegisterAction;
11) FtUILink->getAction = GetRegisterAction;
...
12) lpSetupUIlink = (SetupUIlink)GetProcAddress(hdl,"FP_setupUIlink");
13) if(lpSetupUIlink!=NULL)
{
14) rc=lpSetupUIlink(ftContext,FtUILink,NULL);
...
}
}
}

//---------------------------------------------------------------------------

FP_ACTION __fastcall TForm1::GetRegisterAction (FP_STATUS_PT pStatus, void *pParam)
{
...
15) if(pStatus->code==FT_WAITING)
16) return FT_ID_CONTINUE;
}
//---------------------------------------------------------------------------


Unit1.h

FT_ACTION __fastcall GetRegisterAction (FT_STATUS_PT pStatus, void *pParam);
void __fastcall Button1Click(TObject *Sender);
*********************************************

程序运行报告警告:
W8013 Possible use of 'GetRegisterAction' before definition.
并不会自动调用GetRegisterAction函数.

代码较长,请各位多费心,谢谢!
...全文
135 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wingsun 2000-08-07
  • 打赏
  • 举报
回复
Unit1.cpp

void __fastcall TForm1::Button1Click(TObject *Sender)
{
1) typedef FP_RETCODE _stdcall(*SetupUIlink)(FP_HANDLE,FP_UI_LINK_PT,void *);
2) HINSTANCE hdl; //DLLa模块的句柄
3) FP_RETCODE rc;
4) hdl = LoadLibrary("$$$.dll");
5) if(hdl)
6) { //loadlibrary
...
7) SetupUIlink lpSetupUIlink;
8) FP_UI_LINK_PT FpUILink; //UI link information
9) FpUILink=new FT_UI_LINK; //UI link information
//这是什么意思啊,你有一个成员函数叫GetRegisterAction.还定义一个GetRegisterAction的变量.必将这条语句去掉。
//10) FP_GET_ACTION GetRegisterAction;//

11) FtUILink->getAction = GetRegisterAction;
...
12) lpSetupUIlink = (SetupUIlink)GetProcAddress(hdl,"FP_setupUIlink");
13) if(lpSetupUIlink!=NULL)
{
14) rc=lpSetupUIlink(ftContext,FtUILink,NULL);
...
}
}
}

//---------------------------------------------------------------------------

FP_ACTION __fastcall TForm1::GetRegisterAction (FP_STATUS_PT pStatus, void *pParam)
{
...
15) if(pStatus->code==FT_WAITING)
16) return FT_ID_CONTINUE;
}
//---------------------------------------------------------------------------


Unit1.h

FT_ACTION __fastcall GetRegisterAction (FT_STATUS_PT pStatus, void *pParam);
void __fastcall Button1Click(TObject *Sender);
*********************************************
halfdream 2000-08-06
  • 打赏
  • 举报
回复
而且应该把10这一句去掉
10) FP_GET_ACTION GetRegisterAction;
这句实际是定义了一个函数指针,但没有赋值,
这样11)这一句就没有意义了。
11) FtUILink->getAction = GetRegisterAction;
halfdream 2000-08-06
  • 打赏
  • 举报
回复
你定义的是:
FP_ACTION __fastcall TForm1::GetRegisterAction
你声明的是:
FT_ACTION __fastcall GetRegisterAction
它们可不是同一个东东,当然会提示警告。

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧