Char* to DWORD

Started by
3 comments, last by SiCrane 18 years, 8 months ago
Can someone help me out to covert a char* to a DWORD or DWORD to char* ? thanks.
Advertisement
const char * const foo = "123";DWORD bar = atoi(foo);char buf[1024];itoa(bar,buf,10);
You could just cast the char pointer to a DWORD - the new data-type will of course not actually contain any of the data, but will just be a copy of the pointer:

char *myChars = new char[128];DWORD nDword = (DWORD) myChars;


I've done this with texture pointers and suchlike in my renderState system (D3D uses mostly DWORDs).
If i knew it was this simple i wouldn't asked it ...

Thanks anyway !!!
Assuming C++, you can either use boost::lexical_cast or a std::stringstream.
std::stringstream sstr;sstr << my_dword;char * ptr1 = sstr.str().c_str();std::string str = boost::lexical_cast<std::string>(my_int);char * ptr2 = str.c_str();std::stringstream sstr;sstr.str(char_ptr);DWORD dword1;sstr >> dword1;DWORD dword2 = boost::lexical_cast<DWORD>(char_ptr);

This topic is closed to new replies.

Advertisement