|
-
Dec 16th, 2008, 09:29 AM
#1
Thread Starter
Addicted Member
Usb detection
[Resolved]
I need to detect the usb using the vb....
Here is my code that gets me to DBT_DEVNODES_CHANGED:
*************************************************
Private Sub Form_Load()
SetWindowLong hwnd, GWL_WNDPROC, AddressOf MyWindowProc
End Sub
*************************************************
Public Function MyWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Debug.Print "WM_DEVICECHANGE " & WM_DEVICECHANGE
If Msg = WM_DEVICECHANGE Then
Debug.Print "wParam " & wParam
Select Case wParam
Case &H8000&
Call Form1.DeviceArrival
Case &H8004&
Call Form1.DeviceRemoveComplete
Case &H7&
Dim dbHdr As DEV_BROADCAST_HDR
CopyMemory VarPtr(dbHdr), lParam, Len(dbHdr)
Debug.Print dbHdr.dbch_devicetype
If dbHdr.dbch_devicetype = DEV_BROADCAST_DEVICEINTERFACE Then
Dim dbDdb As DEV_BROADCAST_DEVICEINTERFACE
CopyMemory VarPtr(dbDdb), lParam, Len(dbDdb)
MsgBox dbDdb.dbcc_name
End If
End Select
MyWindowProc = 0
Exit Function
End If
MyWindowProc = CallWindowProc(glngPrevWndProc, hwnd, Msg, wParam, lParam)
End Function
*************************************************
I have the API reference in the module
Declare Sub RegisterDeviceNotification Lib "user32.dll" _
Alias "RegisterDeviceNotificationA" ( _
ByVal hRecipient As Long, _
NotificationFilter As Any, _
ByVal Flags As Long)
*************************************************
I am getting error msg in form load ( invalid use of addressof operator )
please help... Thanks in advance
Last edited by kpmsivachand; Dec 20th, 2008 at 11:00 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|