Advertisement Jump to content
Sign in to follow this  
Codorke

Char* to DWORD

This topic is 4909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

const char * const foo = "123";
DWORD bar = atoi(foo);

char buf[1024];
itoa(bar,buf,10);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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).

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!