FindWindowEx from user32.dll is returning a handle of Zero and error code of 127 using dllimport

Posted by puretechy on Stack Overflow See other posts from Stack Overflow or by puretechy
Published on 2011-03-09T06:02:17Z Indexed on 2012/04/16 11:29 UTC
Read the original article Hit count: 274

Filed under:
|
|
|
|

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#.

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.

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".

This is the link from where I got sample application:

http://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=14519&av=34503

Please help if anyone knows how to solve it.

UPDATE: The DLLImport is:

[DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className,  string  windowTitle);

The Code that is not working is:

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();

© Stack Overflow or respective owner

Related posts about c#

Related posts about winapi