title: 64bit memory address won't fit in Win32(64?)'s API WriteProcessMemory?
body: <p>Alright, so I'm trying to do the old hack the calculator tutorial here:
  <a href="http://www.youtube.com/watch?v=I0zPwg4iUDk" rel="nofollow">http://www.youtube.com/watch?v=I0zPwg4iUDk</a>
  But give it my own spin by adding a form and a button to inject the new value into the calculator. But it keeps spitting out the "can't write to memory" error. Now I dunno why, but I think it's cause my memory address I'm trying to write is from a 64 bit OS. Can anyone tell me why this doesn't work?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  #define IDBUTTON 102
  
  //prototypes
  void injectValue();
  
  using namespace std;
  
  /*  Declare Windows procedure  */
  LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  
  /*  Make the class name into a global variable  */
  char szClassName[ ] = "CodeBlocksWindowsApp";
  HINSTANCE g_hInst;
  int newValue = 500;
  
  int WINAPI WinMain (HINSTANCE hThisInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpszArgument,
                       int nCmdShow)
  {
      HWND hwnd;               /* This is the handle for our window */
      MSG messages;            /* Here messages to the application are saved */
      WNDCLASSEX wincl;        /* Data structure for the windowclass */
  
      /* The Window structure */
      g_hInst = hThisInstance;
      wincl.hInstance = hThisInstance;
      wincl.lpszClassName = szClassName;
      wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
      wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
      wincl.cbSize = sizeof (WNDCLASSEX);
  
      /* Use default icon and mouse-pointer */
      wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
      wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
      wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
      wincl.lpszMenuName = NULL;                 /* No menu */
      wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
      wincl.cbWndExtra = 0;                      /* structure or the window instance */
      /* Use Windows's default colour as the background of the window */
      wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  
      /* Register the window class, and if it fails quit the program */
      if (!RegisterClassEx (&amp;wincl))
          return 0;
  
      /* The class is registered, let's create the program*/
      hwnd = CreateWindowEx (
             0,                   /* Extended possibilites for variation */
             szClassName,         /* Classname */
             "Calculator Trainer",       /* Title Text */
             WS_OVERLAPPEDWINDOW, /* default window */
             CW_USEDEFAULT,       /* Windows decides the position */
             CW_USEDEFAULT,       /* where the window ends up on the screen */
             544,                 /* The programs width */
             375,                 /* and height in pixels */
             HWND_DESKTOP,        /* The window is a child-window to desktop */
             NULL,                /* No menu */
             hThisInstance,       /* Program Instance handler */
             NULL                 /* No Window Creation data */
             );
  
  
      /* Make the window visible on the screen */
      ShowWindow (hwnd, nCmdShow);
  
      /* Run the message loop. It will run until GetMessage() returns 0 */
      while (GetMessage (&amp;messages, NULL, 0, 0))
      {
          /* Translate virtual-key messages into character messages */
          TranslateMessage(&amp;messages);
          /* Send message to WindowProcedure */
          DispatchMessage(&amp;messages);
      }
  
      /* The program return-value is 0 - The value that PostQuitMessage() gave */
      return messages.wParam;
  }
  
  
  /*  This function is called by the Windows function DispatchMessage()  */
  
  LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  {
      HWND hwndButton;
      switch (message)                  /* handle the messages */
      {
          case WM_COMMAND:
            if(((HWND)lParam) &amp;&amp; (HIWORD(wParam) == BN_CLICKED)){
              switch(LOWORD(wParam)){
                case IDBUTTON:{
                     injectValue();
                     break;
                }
                default:
                     break;
              }
            }
            break;
  
  
          case WM_CREATE:
             hwndButton = CreateWindowEx(0,                    /* more or ''extended'' styles */
                       TEXT("BUTTON"),                         /* GUI ''class'' to create */
                       TEXT("Inject Value"),                        /* GUI caption */
                       WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,   /* control styles separated by | */
                       10,                                     /* LEFT POSITION (Position from left) */
                       10,                                     /* TOP POSITION  (Position from Top) */
                       200,                                    /* WIDTH OF CONTROL */
                       30,                                     /* HEIGHT OF CONTROL */
                       hwnd,                                   /* Parent window handle */
                       (HMENU)IDBUTTON,                        /* control''s ID for WM_COMMAND */
                       g_hInst,                                /* application instance */
                       NULL);
             break;
  
          case WM_DESTROY:
              PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
              break;
  
          default:                      /* for messages that we don't deal with */
              return DefWindowProc (hwnd, message, wParam, lParam);
      }
  
      return 0;
  }
  
  void injectValue(){
      cout &lt;&lt; "button pushed" &lt;&lt; endl;
  
      HWND chwnd = FindWindow(0, "Calculator");
      if(chwnd == 0)
          cerr &lt;&lt; "HWND not found!" &lt;&lt; endl;
  
      else{
          DWORD pID;
          GetWindowThreadProcessId(chwnd, &amp;pID);
          HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
  
          if(!hProc)
              cerr &lt;&lt; "Can't open hProc!" &lt;&lt; endl;
  
          else{
              int success = WriteProcessMemory(hProc, (LPVOID) 0xA4283C508C, &amp;newValue, (DWORD_PTR) sizeof(newValue), NULL);
  
              if(success &gt; 0)
                  cout &lt;&lt; "wrote to memory" &lt;&lt; endl;
  
              else
                  cerr &lt;&lt; "Can't write to memory" &lt;&lt; endl;
          }
      }
  }
  </code></pre>