%x expects unsigned. What you type is a pointer. To do this correctly, you usually want to use %p . To be pedantically correct, which expects the pointer to be invalid, you will need to drop it:
printf("%p\n", (void *)val);
In fact, most modern implementations use the same format for all pointers, in which case casting will be empty. Of course, given the C ++ tag, most of the code that you included becomes dubious at best (with the exception of parts like LPSOMESTRUCT, which are dubious independently). In C ++, you usually want something more:
struct somestruct { int a; int b; }; somestruct *val = new somestruct;
source share