' This code is licensed according to the terms and conditions listed here.
' Demonstrate catching an invalid handle error.
' If this code does not work, try replacing "GetLastError()" with Err.LastDllError.
Dim retval As Long ' return value of function
Dim errorcode As Long ' error code
' Make an invalid call to the following function by giving it an invalid handle
retval = CloseHandle(-1) ' there is no handle -1!
If retval = 0 Then ' the return value will be 0 if an error occured
errorcode = GetLastError() ' find the error code
If errorcode = 6 Then Debug.Print "ERROR: Invalid Handle Specified" ' error 6 = invalid handle
End If