Pointers and assignment and unpredictale result

I have a following code:

void *result=GetCurrentApplicationHandler();

long *lngPointer=(long *)result;

printf("\nlngPointer = %d",*lngPointer);

returnValue=*lngPointer;

printf("\nreturnValue = %d",returnValue);

GetCurrentApplicationHandler is a function that returns the pointer to long. I cast it to (long*) pointer and display the value, which displays correctly the value returned by the function. Now I want to pass that value to another function. When I assign this value to returnValue(long) variable, and print it , it displays a garbage value, any ideas, what is missing in above code?

Regards,
Muhammad Farooq
Last edited on
That's could be becuse you are casting the pointer to a variable with different size than the value pointed, try replacing long with some other types
Ok, setting aside the pointer cast magic and assuming it works, the correct format specifier for a long is %ld, not %d.
Topic archived. No new replies allowed.