Using EnumWindows as an example.
PINVOKE EnumWindows is easy. How do you handle the callback.
++PLS
Paul,
>Using EnumWindows as an example.
Great example, since that's covered in the documentation. Just search
for "EnumWindows" and you should find it. Basicly you use a delegate
for the callback parameter.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Hi, inline
> Using EnumWindows as an example.
>
> PINVOKE EnumWindows is easy. How do you handle the callback.
>
> ++PLS
class SomeClass
{
[DllImport..]
private extern static EnumWindows(WndEnumHandler, IntPtr lparam);
private delegate bool WndEnumHandler(IntPtr hParentWnd, IntPtr lparam);
private WndEnumHandler wndEnumHandler; // delegate-instance
public SomeClass()
{
// you must store a reference to the delegate instance, otherwise
// the GC may clean it up.
wndEnumHandler = new WndEnumHandler( OnWndEnum );
}
public void StartEnumWindows(int tag)
{
EnumWindows( wndEnumHandler, new IntPtr(tag) );
}
private bool OnWndEnum( IntPtr hParentWnd, IntPtr lparam )
{
// int tag = lparam.ToInt32();
// use hParentWnd
return true; // or false to stop enumerating
}
}
HTH,
greetings
Mattias Sj?gren - 26 Jul 2004 21:30 GMT
> // you must store a reference to the delegate instance, otherwise
> // the GC may clean it up.
FWIW, you don't have to do that here since EnumWindows makes
synchronous callbacks.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
BMermuys - 27 Jul 2004 19:25 GMT
> > // you must store a reference to the delegate instance, otherwise
> > // the GC may clean it up.
>
> FWIW, you don't have to do that here since EnumWindows makes
> synchronous callbacks.
You're right. Thaught it was async.
Greetings
> Mattias