ImageGear for C and C++ on Linux - Updated
Use Private Data in Callback Functions
User Guide > How to Work with... > Common Operations > Using Callback Functions > Use Private Data in Callback Functions

If you look at the argument lists of the ImageGear callback function types, you will notice that many of them have an argument for holding private data. This can be used for anything you like. In some cases, the function that calls or registers the callback will also contain a parameter for private data, which will be directly passed to your callback. IG_load_file_display() fits this description. In the following example, you will see how the fourth argument of this function can be used to pass private data to the callback for additional flexibility:

 C and C++
Copy Code
LPFNIG_LOAD_DISP   my_set_attributes_func; 
HIGEAR         hIGear;
HDC            hDC;
DWORD          dwGroupID
HWND           hWnd
AT_ERRCOUNT    nErrcount;
AT_MODE        nAlignMode;     /* align mode  */ 
/* Instead of NULL, give the address where private data (&bCenter) begins:*/
nErrcount = IG_load_file_display ( "picture.bmp", hDC, dwGroupID, hWnd,
               my_set_attributes_func, &nAlignMode, &hIGear ); 
/* And the corresponding callback function:  */
VOID ACCUAPI  my_set_attributes_func (LPVOID lpPrivateData, HIGEAR hIGear) 
{
/* Instead of FALSE, give the BOOL value located at the start of the private data
area: */
IG_dspl_layout_set( hIGear, IG_GRP_DEFAULT, IG_DSPL_ALIGN_MODE, NULL, NULL, NULL, 0,
(AT_MODE) *lpPrivateData, 0, 0, 0 ); 
>return;
}
You can pass any amount of private data that you would like. You can define a structure to hold your private data, and can provide the address of the structure (instead of the address of a single variable as in the above example).