GetNextWindow API in C#

T

Tim Mulholland

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.EntryPointNotFoundException' occurred
in MsgTestCSharp.exe
Additional information: Unable to find an entry point named GetNextWindow in
DLL user32.dll.

The most recent way i tried was:

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


what am i doing wrong here?

Thanks in advance,

-Tim
 
N

Nicholas Paldino [.NET/C# MVP]

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("user32.dll", CharSet=CharSet.Auto, EntryPoint="GetWindow",
SetLastError=true)]
public static extern IntPtr GetNextWindow(
IntPtr hwnd,
[MarshalAs(UnmanagedType.U4)] int wFlag);

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

Hope this helps.
 
T

Tim Mulholland

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 said:
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("user32.dll", CharSet=CharSet.Auto, EntryPoint="GetWindow",
SetLastError=true)]
public static extern IntPtr GetNextWindow(
IntPtr hwnd,
[MarshalAs(UnmanagedType.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]
- (e-mail address removed)

Tim Mulholland said:
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.EntryPointNotFoundException'
occurred
in MsgTestCSharp.exe
Additional information: Unable to find an entry point named GetNextWindow
in
DLL user32.dll.

The most recent way i tried was:

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


what am i doing wrong here?

Thanks in advance,

-Tim
 
M

Mattias Sjögren

Tim,
(why make a macro that has a longer name than the original?)

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



Mattias
 

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

Top