A89: Re: Re: Storing pointers to functions in allocated memory...
[Prev][Next][Index][Thread]
A89: Re: Re: Storing pointers to functions in allocated memory...
> To dereference a void pointer and get the value stored there you use the
> "pointer to", i.e. a single "*":
> *((HANDLE *)HeapDeref(old_hook_handle))=old_hook;
>
> Or you could use something else, like:
> memcopy(HeapDeref(old_hook_handle),&old_hook,sizeof(HANDLE));
> which should work but is slower.
Be advised that EV_hook (and, through association, old_hook) are of type
EVENT_HANDLER, which is a function pointer defined as (*EVENT_HANDLER)(EVENT
*ev). Therefore, the correct assignment statement would be:
*((EVENT_HANDLER)HeapDefer(old_hook_handle)) = old_hook;
And, for the original poster, we arrived at that by deferencing the handle,
which returns a void pointer. That pointer is then typecast into a pointer
to an EVENT_HANDERLER (which, by the way, happens to be a pointer to a
function that takes a pointer to struct event). We then dereference that
using the asterisk, which means that we're not storing to the pointer to
that address, but the value in it.
-Scott
Follow-Ups: