Imports System
Imports System.Runtime.InteropServices
Public Delegate Function CallBack( _
hwnd As Integer, lParam As Integer) As Boolean
Public Class EnumReportApp
Declare Function EnumWindows Lib "user32" ( _
x As CallBack, y As Integer) As Integer
Public Shared Sub Main()
EnumWindows(AddressOf EnumReportApp.Report, 0)
End Sub 'Main
Public Shared Function Report(hwnd As Integer, lParam As Integer) _
As Boolean
Console.Write("Window handle is ")
Console.WriteLine(hwnd)
Return True
End Function 'Report
End Class 'EnumReportApp
using System;
using System.Runtime.InteropServices;
public delegate bool CallBack(int hwnd, int lParam);
public class EnumReportApp {
[DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);
public static void Main()
{
CallBack myCallBack = new CallBack(EnumReportApp.Report);
EnumWindows(myCallBack, 0);
}
public static bool Report(int hwnd, int lParam) {
Console.Write("Window handle is ");
Console.WriteLine(hwnd);
return true;
}
}
using namespace System::Runtime::InteropServices;
// A delegate type.
__delegate bool CallBack(int hwnd, int lParam);
// Managed type with the method to call.
__gc class EnumReport
{
// Report the window handle.
public:
bool Report(int hwnd, int lParam) {
Console::Write(L"Window handle is ");
Console::WriteLine(hwnd);
return true;
}
};
[DllImport("user32")]
extern "C" int EnumWindows(CallBack* x, int y);
void main(void) {
EnumReport* er = new EnumReport;
CallBack* myCallBack = new CallBack(er, &EnumReport::Report);
EnumWindows(myCallBack, 0);
}