Several elements in DBTools structures are of type MSG_CALLBACK. These are pointers to callback functions.
Callback functions allow DBTools functions to return control of operation to the user's calling application. The DBTools library uses callback functions to handle messages sent to the user by the DBTools functions for four purposes:
Confirmation Called when an action needs to be confirmed by the user. For example, if the backup directory does not exist, the tools library asks if it needs to be created.
Error message Called to handle a message when an error occurs, such as when an operation is out of disk space.
Information message Called for the tools to display some message to the user (such as the name of the current table being unloaded).
Status information Called for the tools to display the status of an operation (such as the percentage done when unloading a table).
You can directly assign a callback routine to the structure. The following statement is an example using a backup structure:
backup_info.errorrtn = (MSG_CALLBACK) MyFunction |
MSG_CALLBACK is defined in the dllapi.h header file supplied with SQL Anywhere. Tools routines can call back to the calling application with messages that should appear in the appropriate user interface, whether that be a windowing environment, standard output on a character-based system, or other user interface.
The following example confirmation routine asks the user to answer YES or NO to a prompt and returns the user's selection:
extern short _callback ConfirmRtn( char * question ) { int ret = IDNO; if( question != NULL ) { ret = MessageBox( HwndParent, question, "Confirm", MB_ICONEXCLAMATION|MB_YESNO ); } return( ret == IDYES ); } |
The following is an example of an error message handling routine, which displays the error message in a window.
extern short _callback ErrorRtn( char * errorstr ) { if( errorstr != NULL ) { MessageBox( HwndParent, errorstr, "Backup Error", MB_ICONSTOP|MB_OK ); } return( 0 ); } |
A common implementation of a message callback function outputs the message to the screen:
extern short _callback MessageRtn( char * messagestr ) { if( messagestr != NULL ) { OutputMessageToWindow( messagestr ); } return( 0 ); } |
A status callback routine is called when a tool needs to display the status of an operation (like the percentage done unloading a table). A common implementation would just output the message to the screen:
extern short _callback StatusRtn( char * statusstr ) { if( statusstr != NULL ) { OutputMessageToWindow( statusstr ); return( 0 ); } |
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |