Search code examples
c++visual-studiodwordreadprocessmemorybase-address

How to use a HMODULE as a DWORD / Hex value? (C++)


I have a HMODULE value that equals: 00007FF695820000 and I need it to be 0x7FF695820000 but because the value is the correct hex value converting it to hex just makes it an even bigger hex value.

Does anyone know a way I can simply add 0x to the start or make my ReadProcessMemory think this is a hex value not a decimal value.

The reason it's a HMODULE variable is because I'm using it to get the base address for Solitare.exe but currently can't read addresses from it because my ReadProcessMemory just converts it to hex first so reads the wrong address.


Solution

  • Mentioned address 00007FF695820000 is an uint64_t integer number. To call the function you should care about variable type, but not it's visual representation.

    You can read the process memory in the following way:

    UINT_PTR addr = (UINT_PTR)GetModuleHandle("Solitare.exe");
    ReadProcessMemory(hProc, (void*)addr, pBuffer, nSize, &BytesRead);
    

    To use ReadProcessMemory your hProc handle should have PROCESS_VM_READ access permission.