I am trying to display memory address of a function in a MessageBox, but it doesn't display it as I want.
I want to pass a function address of a callback function to another function, so I tried to get its address.
I looked at this example and tried to show it in a MessageBox first instead printing to console, before using it.
How I tried it:
char ** fun()
{
static char * z = (char*)"Merry Christmas :)";
return &z;
}
int main()
{
char ** ptr = NULL;
char ** (*fun_ptr)(); //declaration of pointer to the function
fun_ptr = &fun;
ptr = fun();
char C[256];
snprintf(C, sizeof(C), "\n %s \n Address of function: [%p]", *ptr, fun_ptr);
MessageBoxA(nullptr, C, "Hello World!", MB_ICONINFORMATION);
snprintf(C, sizeof(C), "\n Address of first variable created in fun() = [%p]", (void*)ptr);
MessageBoxA(nullptr, C, "Hello World!", MB_ICONINFORMATION);
return 0;
}
But, these messageboxes display very large numbers and they seems null.
I like to display them in a messagebox exactly like in linked post's example outputs.
Thanks in Advance.