title: Read text from notepad process memory
body: <p>I want to read the entire memory of notepad, and write the output to a text file.
  If I type something in notepad, I do not find what I type in the output.
  This is the code:</p>
  
  <pre><code>HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
  char* ptr = 0;
  MEMORY_BASIC_INFORMATION info;
  while(ptr&lt;=(char*)0x7FFF0000)
  {
      VirtualQueryEx(hProcess,(LPCVOID)ptr,&amp;info,sizeof(info));
      if((info.AllocationProtect==0x04) || (info.AllocationProtect==0x10) || 
         (info.AllocationProtect==0x20) || (info.AllocationProtect==0x40) || 
         (info.AllocationProtect==0x80) || (info.AllocationProtect==0x02) || 
         (info.AllocationProtect==0x08))
      {
          int bytes_to_read = (int)info.RegionSize;
          char *buffer = NULL;
          buffer = (char *)malloc(info.RegionSize);
          ReadProcessMemory(hProcess,
                            info.BaseAddress,
                            &amp;buffer,
                            bytes_to_read,
                            NULL);
          ofstream out;
          out.open("test.txt",ios_base::app);
          out &lt;&lt; buffer;
          out.close();
      }
      ptr += info.RegionSize;
  }
  </code></pre>