简体   繁体   中英

How to pass a function pointer as a parameter to a function?

Ok so I have the following typedef declaration:

typedef void (__fastcall* INFINITYHOOKCALLBACK)(_In_ unsigned int SystemCallIndex, _Inout_ void** SystemCallFunction);

and I have the following function declaration:

NTSTATUS IfhInitialize(
_In_ INFINITYHOOKCALLBACK InfinityHookCallback);

So my question is how would I declare and define a CallBack function that can be passed to the above function?

Just define it following the typedef:

void __fastcall MyCallback(unsigned int SystemCallIndex, void** SystemCallFunction) {
// ...
}

And pass it with its name:

IfhInitialize(MyCallback);

The function pointer type in question takes two parameters of type unsigned int and void ** and has return type void . So a function signature like the following would be compatible with this:

void __fastcall mycallback(unsigned int SystemCallIndex, void **SystemCallFunction);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM