title: Allocating memory using AWE
body: <p>I'm using 32bit Windows XP SP3 with PAE enabled and 8GB physical memory.</p>
  
  <p>All i want is to use AWE to allocate memory from the dark side - i.e. the hidden 4GB - so i wrote i gave my user <code>Lock pages in memory</code> right then i wrote the following code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  
  BOOL EnableAWE();
  
  int main()
  {
      if(!EnableAWE())
      {
          printf("Can not enable AWE on this system.\n");
          return 1;
      }
  
      HANDLE hProcess = GetCurrentProcess();
      SIZE_T byts = ~0u &gt;&gt; 1;
      LPVOID ptr = VirtualAllocEx(hProcess, NULL, byts, MEM_PHYSICAL | MEM_RESERVE, PAGE_READWRITE);
  
      if (ptr == NULL)
      {
          printf("Allocation failed for requested memory size.\n");
          return 1;
      }
  
      VirtualFreeEx(hProcess, ptr, 0, MEM_RELEASE);
  
      return 0;
  }
  
  BOOL EnableAWE()
  {
      HANDLE hToken = NULL;
  
      TOKEN_PRIVILEGES tp;
      tp.PrivilegeCount = 1;
      tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  
      if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &amp;hToken)) return FALSE;
      if (!LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &amp;(tp.Privileges[0].Luid))) return FALSE;
      if (!AdjustTokenPrivileges(hToken, FALSE, &amp;tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) return FALSE;
  
      return TRUE;
  }
  </code></pre>
  
  <p>the function <code>EnableAWE</code> always return true, but when i try to allocate the 2GB using <code>VirtualProtect</code> it fails with error code 87 which means <code>The parameter is incorrect.</code></p>
  
  <p>i don't know which parameter is incorrect.</p>
  
  <p>thanks.</p>