Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

convert char* to DWORD?

This topic is 2603 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




char *string1 = "hithere";

void function(DWORD dwAddy)
{
.
.
}


int main()
{

function( string1 );

return 0;
}



how do i pass the address of my hardcoded string( "hithere" ) into my function and store the address in a DWORD( int ) ? thanks

Share this post


Link to post
Share on other sites
Advertisement
how many bits are in your address? 32? and in DWORD? 32? then you can just cast it:

function( (DWORD)string1 );

whether this is 'safe' or 'correct' or 'best practice' can be the subject of discussion...

Share this post


Link to post
Share on other sites
[font="'Courier New"]*reinterpret_cast<DWORD*>(&string1)[/font]

but this is not safe to do according to the standard. It definitely won't work on compilers where [font="'Courier New"]sizeof(DWORD) < sizeof(char*)[/font]

Share this post


Link to post
Share on other sites
1 more thing, how do i get visual studio to print me the pointer value of the following?

(*((BYTE*)(dwAddress+i))) ) <---- visual studio will let me breakpoint and hover mouse over variable "dwaddress" and get it's current contents because it's a variable. But how do i make visual studio tell me the value of the casted pointer "(*((BYTE*)(dwAddress+i))) )" when i mouse over it doesnt give me options to view the dereferenced pointer value? how do i make it show me?

Share this post


Link to post
Share on other sites
Why are you trying to do this? Especially relevant considering you are posting in For Beginners.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!