-
Callback type things
I have this code currently:
Code:
void (*OnPaint)(WindowArgs, PaintArgs);
It works like I want it to, the user creates a void function with the arguments it says there (they are alreayd defined structs) and than the user simple does
Code:
OnPaint = func_name;
And they decalre the function like this:
Code:
void paint(WindowArgs args, PaintArgs paint)
{
//Do stuff here
}
But the thing is I want the user know what kind of arguments to put inside the callback without looking at the callback code. It is a very vague question so I hope someone can help me. Ask if you need any more info.
-
If you're wondering how to call a function pointer:
Code:
void (*funcp1)(int) = function, (*funcp2)(int) = &function;
(*funcp1)(5);
funcp1(5);
As you can see, there are two ways to assign and call function pointers.
-
ahh ok I see, I think I got some ideas now. Thanks.
-
The user can not be completely ignorant of the implementation details, they will have to make a callback function with the specified parameters before you can appropriately pass a function pointer around as a callback, bowever you can ease the complex syntax using typedef's. For example, take the API function BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam); The WNDENUMPROC is a user-defined callback, WNDENUMPROC is typedef'd as "typedef BOOL (CALLBACK* WNDENUMPROC)(HWND, LPARAM);" This means a user would define their callback like:
Code:
BOOL MyEnumWindowsCallback(HWND hWnd, LPARAM lParam)
{
return 0;
}
And then call the function with:
Code:
EnumWindows(&MyEnumWindowsProc, someSortOflParamValue);