• Advertisement
Sign in to follow this  

convert char* to DWORD?

This topic is 2393 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
Sign in to follow this  

  • Advertisement