I tried to use while
, but the effect is not very good. Is there any way to do it?
bool found = false;
uintptr_t memaddr = 0;
int n = 0;
while (!found && n < 10)
{
n += 1;
memaddr = (uintptr_t)VirtualAlloc(0, 4, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
int g = memaddr / 1024 / 1024 / 1024;
cout << "memaddr: " << memaddr << endl;
if (g >= 2 && g <= 4)
{
found = true;
}
}
cout << hex << memaddr << endl;