title: FindWindowEx from user32.dll is returning a handle of Zero and error code of 127 using dllimport
body: <p>I need to handle another windows application programatically, searching google I found a sample which handles windows calculator using DLLImport Attribute and importing the user32.dll functions into managed ones in C#.</p>
  
  <p>The application is running, I am getting the handle for the main window i.e. Calculator itself, but the afterwards code is not working. The FindWindowEx method is not returning the handles of the children of the Calculator like buttons and textbox.</p>
  
  <p>I have tried using the SetLastError=True on DLLImport and found that I am getting an error code of 127 which is "Procedure not found".</p>
  
  <p>This is the link from where I got sample application:</p>
  
  <p><a href="http://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=14519&amp;av=34503" rel="noreferrer">http://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=14519&amp;av=34503</a></p>
  
  <p>Please help if anyone knows how to solve it.</p>
  
  <p>UPDATE: The DLLImport is:</p>
  
  <pre><code>[DllImport("user32.dll", SetLastError = true)]
          public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className,  string  windowTitle);
  </code></pre>
  
  <p>The Code that is not working is:</p>
  
  <pre><code>hwnd=FindWindow(null,"Calculator"); // This is working, I am getting handle of Calculator
  
  // The following is not working, I am getting hwndChild=0 and err = 127
  hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","1");
  
                  Int32 err = Marshal.GetLastWin32Error();
  </code></pre>