convert char* to DWORD?

Started by
4 comments, last by rip-off 12 years, 6 months ago



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
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...
[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]
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?
Copy that snippet of code and paste it into the 'Watch' debugging window.
Why are you trying to do this? Especially relevant considering you are posting in For Beginners.

This topic is closed to new replies.

Advertisement