Callback type things
I have this code currently:
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
void (*OnPaint)(WindowArgs, PaintArgs);
And they decalre the function like this:
OnPaint = func_name;
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.
void paint(WindowArgs args, PaintArgs paint)
//Do stuff here
If you're wondering how to call a function pointer:
As you can see, there are two ways to assign and call function pointers.
void (*funcp1)(int) = function, (*funcp2)(int) = &function;
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:
And then call the function with:
BOOL MyEnumWindowsCallback(HWND hWnd, LPARAM lParam)