Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21152

[RESOLVED] Can't get AddressOf to work.

$
0
0
Hi all!

I've tried several snippets and get the same result every time.
Im using VB6 SP5, developing on WinXP SP3

Here's a simple segment that should work but gives the error:
"Invalid use of AddressOf operator."

Code:

Private Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private Sub Form_Load()

    Call Main
   
End Sub


Public Sub Main()
' Main starts the enumeration, pass the address of the callback function

    Debug.Print "============================="
    Debug.Print " Start of enumeration:"
   
    If EnumWindows(AddressOf EnumWindows_CallBack, 0) = 0 Then
        Err.Raise 12345, , "Could not enumerate all windows!"
    End If
   
    Debug.Print "============================="
   
End Sub


Private Function EnumWindows_CallBack(ByVal hWnd As Long, ByVal lParam As Long) As Long
' This function is called from the EnumWindows API

    Debug.Print "hWnd Found: " & hWnd
    EnumWindows_CallBack = 1  ' The API ends if we return false
 
End Function

Can someone help?
Thanks!

Viewing all articles
Browse latest Browse all 21152

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>