EnumChildWindows (Win32 error 127) (c#)

  • Thread starter Thread starter Ryan Ross
  • Start date Start date
R

Ryan Ross

Hello,

I am having the oddest error with the EnumChildWindows function. Below are
the imports, and the methods.

[DllImport("user32.dll", SetLastError=true)]

public static extern int EnumChildWindows(IntPtr hWndParent, EnumChildProc
callback, int lParam);

public delegate int EnumChildProc(IntPtr hwnd, long lParam);



public void M_initChildWindows()

{

if(WindowObject_Basic_GDI_Handle != IntPtr.Zero)

{

try

{

User32.EnumChildWindows(WindowObject_Basic_GDI_Handle, new
User32.EnumChildProc(M_addChildWindows), 0);

}

catch(Exception e)

{

System.Diagnostics.Debug.WriteLine("Child Window failure: " +
e.Message);

}

}


}

private int M_addChildWindows(IntPtr Window, long Data)

{


if(Window != IntPtr.Zero)

{

ChildWindowObject_Basic c_WindowObject_Basic = new
ChildWindowObject_Basic(Window);

c_WindowObject_Basic_Array.Add(c_WindowObject_Basic);

}




return 1;

}



I keep getting a 127 error, even though it appears to enumerate the windows.
I placed it within a try statement to continue working other things, but
it's coming back to bite me in the ass.



Anyone have any ideas?



Thanks,

Ryan
 
Ryan,

Your declaration of the callback delegate and function is incorrect. It
should be:

[DllImport("user32.dll", SetLastError=true)]
public static extern int EnumChildWindows(IntPtr hWndParent, EnumChildProc
callback, IntPtr lParam);

public delegate int EnumChildProc(IntPtr hwnd, IntPtr lParam);

LPARAM translates to an IntPtr.

Also, as an aside, you might want to check your publicly exposed method
names. They violate the public naming convention (M_initChildWindows, for
example).

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top