EnumWindows Problem

I need to call the EnumWindows API function within my VB program, but I'm getting an error "Invalid use of AddressOf operator." I am making the call from the code module attached to a form.

Can you help?
Thanks!!

Here is my code
======================================
'''
'Windows API Function Declarations
''
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

'''''
'Here is the point where the error occurs:
'''''
vEnumRet = EnumWindows(AddressOf EnumWindowsProc, ByVal 0&)

'''''
'here is my callback:
'''''
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
Debug.Print Str$(hwnd) + " " + sSave
'continue enumeration
EnumWindowsProc = True
End Function
[1617 byte] By [SteveMurphy] at [2007-11-19 7:27:18]
# 1 Re: EnumWindows Problem
Are you trying to run this in the IDE? I'm pretty sure callbacks will only work on compiled projects. As far as the syntax goes, the function returns a boolean, so try assigning the return to a hard-typed variable.
Comintern at 2007-11-9 20:44:38 >
# 2 Re: EnumWindows Problem
Hi Comintern,

1) Yes, I was trying to run the app in the IDE, but when I tried compiling the app, I got the same error message.

2) I had actually declared the return value variable, but neglected to include that in the code snippet. Here is the declaration:
Dim vEnumRet As Boolean

Any other ideas?
SteveMurphy at 2007-11-9 20:45:44 >
# 3 Re: EnumWindows Problem
Only other idea I have is that you have to place the callback function in a module. I'm also assuming that you are using VB=>5.
Comintern at 2007-11-9 20:46:42 >
# 4 Re: EnumWindows Problem
you need to use a module, not a form. alternatively, use this pre-made bas i wrote a long time ago:

WindowInteraction.bas
cjard at 2007-11-9 20:47:43 >
# 5 Re: EnumWindows Problem
CJard,

Thanks! I really liked your module - very clever.
SteveMurphy at 2007-11-9 20:48:42 >