EnumChildWindows (Win32 error 127) (c#)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan Ross

    EnumChildWindows (Win32 error 127) (c#)

    Hello,

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

    [DllImport("user 32.dll", SetLastError=tr ue)]

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

    public delegate int EnumChildProc(I ntPtr hwnd, long lParam);



    public void M_initChildWind ows()

    {

    if(WindowObject _Basic_GDI_Hand le != IntPtr.Zero)

    {

    try

    {

    User32.EnumChil dWindows(Window Object_Basic_GD I_Handle, new
    User32.EnumChil dProc(M_addChil dWindows), 0);

    }

    catch(Exception e)

    {

    System.Diagnost ics.Debug.Write Line("Child Window failure: " +
    e.Message);

    }

    }


    }

    private int M_addChildWindo ws(IntPtr Window, long Data)

    {


    if(Window != IntPtr.Zero)

    {

    ChildWindowObje ct_Basic c_WindowObject_ Basic = new
    ChildWindowObje ct_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


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: EnumChildWindow s (Win32 error 127) (c#)

    Ryan,

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

    [DllImport("user 32.dll", SetLastError=tr ue)]
    public static extern int EnumChildWindow s(IntPtr hWndParent, EnumChildProc
    callback, IntPtr lParam);

    public delegate int EnumChildProc(I ntPtr 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_initChildWin dows, for
    example).

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Ryan Ross" <ryanr@nni.co m> wrote in message
    news:5OmdnTWIFr 7rIbTeRVn-oA@nni.com...[color=blue]
    > Hello,
    >
    > I am having the oddest error with the EnumChildWindow s function. Below are
    > the imports, and the methods.
    >
    > [DllImport("user 32.dll", SetLastError=tr ue)]
    >
    > public static extern int EnumChildWindow s(IntPtr hWndParent, EnumChildProc
    > callback, int lParam);
    >
    > public delegate int EnumChildProc(I ntPtr hwnd, long lParam);
    >
    >
    >
    > public void M_initChildWind ows()
    >
    > {
    >
    > if(WindowObject _Basic_GDI_Hand le != IntPtr.Zero)
    >
    > {
    >
    > try
    >
    > {
    >
    > User32.EnumChil dWindows(Window Object_Basic_GD I_Handle, new
    > User32.EnumChil dProc(M_addChil dWindows), 0);
    >
    > }
    >
    > catch(Exception e)
    >
    > {
    >
    > System.Diagnost ics.Debug.Write Line("Child Window failure: " +
    > e.Message);
    >
    > }
    >
    > }
    >
    >
    > }
    >
    > private int M_addChildWindo ws(IntPtr Window, long Data)
    >
    > {
    >
    >
    > if(Window != IntPtr.Zero)
    >
    > {
    >
    > ChildWindowObje ct_Basic c_WindowObject_ Basic = new
    > ChildWindowObje ct_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
    >
    >[/color]


    Comment

    Working...