I'm trying to convert a float value (0.75) to hex and write that converted value to memory.
char Actual[4];
float f = 0.75f;
int i = *(reinterpret_cast<int*>(&f));
wsprintf(Actual, "%08X", i);
MessageBox(NULL, Actual, "Float", NULL);
unsigned long OldProtection;
VirtualProtect((LPVOID)(0x01234567), 4, PAGE_EXECUTE_READWRITE, &OldProtection);
memcpy((LPVOID)0x01234567, Actual, 4);
VirtualProtect((LPVOID)(0x01234567), 4, OldProtection, NULL);
The conversion works quite well and outputs the correct value (3F400000) when using MessageBox.
But when writing the converted value to memory using memcpy the value of the target address is 30303030 and not 3F400000.
I guess I'm missing some additional step. What could be the problem?
0x01234567seems pretty dangerous to me.