GetNextWindow API in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Mulholland

    GetNextWindow API in C#

    I'm trying to call the GetNextWindow API function via C#.

    I've tried two different definitions for it (both are similar), but i always
    get the same error:

    An unhandled exception of type 'System.EntryPo intNotFoundExce ption' occurred
    in MsgTestCSharp.e xe
    Additional information: Unable to find an entry point named GetNextWindow in
    DLL user32.dll.

    The most recent way i tried was:

    [DllImport("user 32.dll", CharSet=CharSet .Auto)]
    public static extern IntPtr GetNextWindow(I ntPtr hwnd, IntPtr wFlag);


    what am i doing wrong here?

    Thanks in advance,

    -Tim


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: GetNextWindow API in C#

    Tim,

    GetNextWindow isn't actually an API function, but rather, a macro that
    just calls GetWindow. So you should define GetWindow, and call that. If
    you really want to call a method named GetNextWindow, then you can define
    the entry point, like this:

    [DllImport("user 32.dll", CharSet=CharSet .Auto, EntryPoint="Get Window",
    SetLastError=tr ue)]
    public static extern IntPtr GetNextWindow(
    IntPtr hwnd,
    [MarshalAs(Unman agedType.U4)] int wFlag);

    I changed the wFlag parameter because it would end up failing on 64-bit
    systems.

    Hope this helps.


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

    "Tim Mulholland" <TimMulholland@ nospamaddress.c om> wrote in message
    news:e8XJVMk0EH A.2196@TK2MSFTN GP14.phx.gbl...[color=blue]
    > I'm trying to call the GetNextWindow API function via C#.
    >
    > I've tried two different definitions for it (both are similar), but i
    > always
    > get the same error:
    >
    > An unhandled exception of type 'System.EntryPo intNotFoundExce ption'
    > occurred
    > in MsgTestCSharp.e xe
    > Additional information: Unable to find an entry point named GetNextWindow
    > in
    > DLL user32.dll.
    >
    > The most recent way i tried was:
    >
    > [DllImport("user 32.dll", CharSet=CharSet .Auto)]
    > public static extern IntPtr GetNextWindow(I ntPtr hwnd, IntPtr wFlag);
    >
    >
    > what am i doing wrong here?
    >
    > Thanks in advance,
    >
    > -Tim
    >
    >[/color]


    Comment

    • Tim Mulholland

      #3
      Re: GetNextWindow API in C#

      I dug into the .dll with depends and found that out for myself just a few
      minutes ago.
      I had read that a while back, but i thought it was the other way around (why
      make a macro that has a longer name than the original?)

      Thanks for the top on the one parameter.

      -Tim

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:eea78dk0EH A.3820@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Tim,
      >
      > GetNextWindow isn't actually an API function, but rather, a macro that
      > just calls GetWindow. So you should define GetWindow, and call that. If
      > you really want to call a method named GetNextWindow, then you can define
      > the entry point, like this:
      >
      > [DllImport("user 32.dll", CharSet=CharSet .Auto, EntryPoint="Get Window",
      > SetLastError=tr ue)]
      > public static extern IntPtr GetNextWindow(
      > IntPtr hwnd,
      > [MarshalAs(Unman agedType.U4)] int wFlag);
      >
      > I changed the wFlag parameter because it would end up failing on[/color]
      64-bit[color=blue]
      > systems.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Tim Mulholland" <TimMulholland@ nospamaddress.c om> wrote in message
      > news:e8XJVMk0EH A.2196@TK2MSFTN GP14.phx.gbl...[color=green]
      > > I'm trying to call the GetNextWindow API function via C#.
      > >
      > > I've tried two different definitions for it (both are similar), but i
      > > always
      > > get the same error:
      > >
      > > An unhandled exception of type 'System.EntryPo intNotFoundExce ption'
      > > occurred
      > > in MsgTestCSharp.e xe
      > > Additional information: Unable to find an entry point named[/color][/color]
      GetNextWindow[color=blue][color=green]
      > > in
      > > DLL user32.dll.
      > >
      > > The most recent way i tried was:
      > >
      > > [DllImport("user 32.dll", CharSet=CharSet .Auto)]
      > > public static extern IntPtr GetNextWindow(I ntPtr hwnd, IntPtr wFlag);
      > >
      > >
      > > what am i doing wrong here?
      > >
      > > Thanks in advance,
      > >
      > > -Tim
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Mattias Sjögren

        #4
        Re: GetNextWindow API in C#

        Tim,
        [color=blue]
        >(why make a macro that has a longer name than the original?)[/color]

        It started out as a real function in the Win16 API. In Win32 it's a
        macro mostly available for backward compatibility.



        Mattias

        --
        Mattias Sjögren [MVP] mattias @ mvps.org
        http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
        Please reply only to the newsgroup.

        Comment

        Working...