title: Error while getting the process id
body: <p>I'm creating a clipboard monitor as a project and on clipboard change the application detects which program has used the clipboard by calling the GetClipboardOwner.</p>
  
  <p>This is an excerpt from the code:</p>
  
  <pre><code>protected override void WndProc(ref Message m)
          {
              const int WM_DRAWCLIPBOARD = 0x308;
              const int WM_CHANGECBCHAIN = 0x030D;
  
              switch (m.Msg)
              {
                  case WM_DRAWCLIPBOARD:
                      Debug.Indent();
                      //Process the clipboard here
                      uint processId;
                      IntPtr ownerHwnd = GetClipboardOwner();
                      GetWindowThreadProcessId(ownerHwnd, out processId);
                      Process proc = Process.GetProcessById((int)processId);
                      Debug.WriteLine(String.Format("Window Title: {0} Filename: {1}", proc.MainWindowTitle, process.MainModule.FileName));
                      SendMessage(_NextClipboardViewer, m.Msg, m.WParam, m.LParam);
                      break;
  
                  case WM_CHANGECBCHAIN:
                      if (m.WParam == _NextClipboardViewer)
                          _NextClipboardViewer = m.LParam;
                      else
                          SendMessage(_NextClipboardViewer, m.Msg, m.WParam, m.LParam);
                      break;
  
                  default:
                      base.WndProc(ref m);
                      break;
              }
          }
  </code></pre>
  
  <p>and the DLLImports:</p>
  
  <pre><code>[DllImport("User32.dll")]
          public static extern IntPtr SetClipboardViewer(IntPtr _newviewerhandle);
  
  [DllImport("User32.dll")]
          public static extern bool ChangeClipboardChain(IntPtr removehandle, IntPtr nexthandle);
  
  [DllImport("User32.dll")]
          public static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
  
  [DllImport("User32.dll")]
          public static extern IntPtr GetClipboardOwner();
  
  [DllImport("kernel32.dll")]
          public static extern int GetWindowThreadProcessId(IntPtr handle, out uint threadid);
  </code></pre>
  
  <p>Exception in Output window is - A first chance exception of type 'System.EntryPointNotFoundException' occurred in Something.exe</p>
  
  <p><strong>UPDATE 2</strong> After changing "Kernel32" to "User32", it works but for some applications like Word, Excel, I get this exception; A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll</p>
  
  <p>Any ideas ? </p>
  
  <p><strong>UPDATE 3</strong> The above exception was caused due to a 32-bit process (my application) accessing the module of a 64-bit process (Word, Excel, etc.)
  Changing the configuration to x64 worked.</p>