Viewing memory address

Started by
2 comments, last by HappyToLearnC 21 years, 6 months ago
Hi What casting I should use to make a pointer of any type prints to a MessageBox second parameter. For example struct sFrame{} sFrame *sFrame1; MessageBox(NULL,sFrame1,""MB_OK); Well, I want to know the memory location for sFrame1. ManyThanks
God is the greatest
Advertisement
You need to create a string with the address, not do a cast (unless you use boost::lexical_cast).


  #include <sstream>struct Foo {};Foo f;int main(){   // create an output string stream   std::ostringstream oss;   // write the address of f to the stream   oss << &f  // or possibly oss << (void*)&f   // extract the string from the stream,   // then pass it as a const char* string to MessageBox   MessageBox( NULL, oss.str().c_str(), "", MB_OK );   // clears the flags in oss (if the object is reused)   oss.clear();      // clear the string in oss (if the object is reused)   oss.str("");   };  


Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Try using sprintf() and then passing the buffer that you got from that to the MessageBox().

I know printf() can do addresses so sprintf() should be able to also.

Er.. I just noticed the one above me says how to do it also...
Well, this is just a different way. Take your pick

[edited by - Soulkeeper on October 19, 2002 2:17:16 AM]
I'm learning, just like the best of us...Ok, now assume a spherical cow... :)
You are great

God is the greatest

This topic is closed to new replies.

Advertisement