title: VirtualProtectEx function failing - error 487, only on Windows XP
body: <p>Allow me to clarify, this code works 100% on Windows Vista and Windows 7, however, the function <code>VirtualProtectEx</code>  fails on Windows XP with a <code>GetLastError()</code> code of 487 - ERROR_INVALID_ADDRESS.</p>
  
  <p>Here is the function associated:</p>
  
  <pre><code>int HpRemoteHookInstall(__in HANDLE m_hProcess, __in LPVOID m_pvTargetAddress, __in LPVOID m_pvRedirectAddress) {
  // Misc checks
  if ( m_pvTargetAddress == NULL || m_pvRedirectAddress == NULL )
  {
      return -1;
  }
  
  DWORD  m_dwOldRights         = NULL;
  BYTE   m_btHotPatch[7];
  
  ZeroMemory(m_btHotPatch, sizeof(m_btHotPatch));
  
      // m_hProcess - remote process
  // m_pvTargetAddress - remote base
  // Allow write access - code will be restored later on
  if ( VirtualProtectEx(m_hProcess, (LPVOID)m_pvTargetAddress, 6, PAGE_EXECUTE_READWRITE, &amp;m_dwOldRights) == FALSE )
  {
      DisplayError(); // displays getlasterror function in messagebox
      return -2;
  }
  </code></pre>
  
  <p>What could I possibly be doing wrong?
  Thank you for your time.</p>
  
  <p><strong>Edit</strong> - The m_pvTargetAddress value is constant on each operating system (meaning the same on every execution), but differ between the three OS's</p>
  
  <p><strong>Edit</strong> - I obtain the m_pvTargetAddress through GetThreadContex(Remote thread) -> Eip of the context</p>
  
  <p><strong>Edit</strong> - Here are the values VirtualQueryEx returned when called:</p>
  
  <p><strong>Windows XP</strong> </p>
  
  <ul>
  <li>0 - allocation base</li>
  <li>0 - allocation protect</li>
  <li>2088828928 - base address</li>
  <li>1 - protect</li>
  <li>983040 - region size</li>
  <li>65536 - state</li>
  <li>0 - type</li>
  </ul>
  
  <p><strong>Windows 7</strong></p>
  
  <ul>
  <li>2003959808 - allocation base</li>
  <li>128 - allocation protect</li>
  <li>2004025344 - base address</li>
  <li>32 - protect</li>
  <li>876544 - region size</li>
  <li>4096 - state</li>
  <li>16777216 - type</li>
  </ul>
  
  <p><strong>Windows Vista</strong></p>
  
  <ul>
  <li>2006122496 - allocation base</li>
  <li>128 - allocation protect</li>
  <li>2006536192 - Base address</li>
  <li>32 - protect</li>
  <li>389120 - region size</li>
  <li>4096 - state</li>
  <li>16777216 - type</li>
  </ul>