|
-
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.
-
Dec 16th, 2008, 03:20 PM
#2
Addicted Member
Re: Usb detection
Move your MyWindowProc function into your code module.
-
Dec 16th, 2008, 08:46 PM
#3
Thread Starter
Addicted Member
Re: Usb detection
thanks for your reply... its already there only
-
Dec 16th, 2008, 08:49 PM
#4
Thread Starter
Addicted Member
-
Dec 16th, 2008, 09:31 PM
#5
-
Dec 16th, 2008, 11:54 PM
#6
Thread Starter
Addicted Member
Re: Usb detection
hello dee-u! thank you dude.... this what i expect... once again thanks for the links....
-
Dec 17th, 2008, 05:19 AM
#7
Re: Usb detection
No problem. You can now mark this thread as resolved using the Thread Tools menu.
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
|