Home > Archive > Visual Basic > February 2005 > Detecing USB changes / sysinfo.ocx and supported events
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Detecing USB changes / sysinfo.ocx and supported events
|
|
| Duncan Hughes 2005-02-18, 8:55 am |
| Hi,
I have been looking for a little while at detecting the change of USB
devices (VB6.0 SP5). I have been looking at using "hooking" Windows Messages
through the API with some limited success, but recently found sysinfo.ocx
After jumping up and down with joy I started looking for some examples on
the web as I could not seem to get the events for the devicearriavl etc. to
fire. I have since found a couple of sites that explain all the events I need
do not actually work in the control!!!
Is this correct?
Secondly. I can detect the removal/change of a device using the API but do
not seem able to get a friendlyname of the device. If I plug my USB camera
into my XP machine I get a balloon tip telling me it's a Logitect xxxxx
camera. But how can I get this information.
Any examples, hints or pointers to related material would be apprectiated.
Many thanks
Duncan.
| |
| Dick Grier 2005-02-18, 3:55 pm |
| Hi,
Here is my USB FAQ. Some of it applies to your question (Jan's book).
There isn't a simple answer -- you have to know a lot about the USB
implementation used by your device.
You normally use whatever API is required for the specific hardware device
that is attached to the USB port. There is no general-purpose driver for
this. So, if you are connecting to a serial device, you use the Windows
serial APIs. If a sound device, you use the MCI APIs. If a disk drive, you
use the various file APIs. The actual driver that is installed when Windows
detects the USB device translates these Windows APIs to the device specific
commands required for the actual hardware.
However, if you have custom built USB hardware, you need lower level access
to the device. You must know A LOT about the hardware before this sort of
thing is useful. I suggest that you get a copy of Jan Axelson's book, USB
Complete, 2nd Edition. You can get information on it from the Books link on
my homepage.
If you just want to use a USB serial port adapter to connect to an RS-232
device, then you may use MSComm or any of the other serial communications
methods that are described in detail in my book.
--
Richard Grier (Microsoft Visual Basic MVP)
See www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
| |
| Duncan 2005-02-20, 8:55 pm |
| there seems to be more to this than I originally thought,
Thanks for the response. Perhaps I'll take a look at the book.
Duncan.
"Dick Grier" wrote:
> Hi,
>
> Here is my USB FAQ. Some of it applies to your question (Jan's book).
> There isn't a simple answer -- you have to know a lot about the USB
> implementation used by your device.
>
> You normally use whatever API is required for the specific hardware device
> that is attached to the USB port. There is no general-purpose driver for
> this. So, if you are connecting to a serial device, you use the Windows
> serial APIs. If a sound device, you use the MCI APIs. If a disk drive, you
> use the various file APIs. The actual driver that is installed when Windows
> detects the USB device translates these Windows APIs to the device specific
> commands required for the actual hardware.
>
> However, if you have custom built USB hardware, you need lower level access
> to the device. You must know A LOT about the hardware before this sort of
> thing is useful. I suggest that you get a copy of Jan Axelson's book, USB
> Complete, 2nd Edition. You can get information on it from the Books link on
> my homepage.
>
> If you just want to use a USB serial port adapter to connect to an RS-232
> device, then you may use MSComm or any of the other serial communications
> methods that are described in detail in my book.
>
> --
> Richard Grier (Microsoft Visual Basic MVP)
>
> See www.hardandsoftware.net for contact information.
>
> Author of Visual Basic Programmer's Guide to Serial Communications, 4th
> Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
> www.mabry.com/vbpgser4 to order.
>
>
>
| |
| Duncan 2005-02-28, 3:55 pm |
| Since my last post I have been able to get as far as intoducing
RegisterDeviceNotification into my code so that I am able to get more
information on the device. However, I am now stuck again. This is the
information I get from
"Dim dbDdb As DEV_BROADCAST_DEVICEINTERFACE"
dbDdb.dbcc_size=192
dbDdb.dbcc_devicetype=5
dbDdb.dbcc_reserved=0
dbDdb.dbcc_name=1547656284
Device Name:
Where Device Name: = StringFromPointer(ByVal (dbDdb.dbcc_name))
**************************
Public Function StringFromPointer(ByVal lPointer As Long) As String
Dim strTemp As String
Dim lRetVal As Long
'prepare the strTemp buffer
strTemp = String$(lstrlen(ByVal lPointer), 0)
'copy the string into the strTemp buffer
lRetVal = lstrcpy(ByVal strTemp, ByVal lPointer)
'return a string
If lRetVal Then StringFromPointer = strTemp
End Function
**************************
As you can see the Device name is empty/blank. Also I understand that
"dbDdb.dbcc_size=192" is incorrect and according to Microsoft, for
device_type DBT_DEVTYP_DEVICEINTERFACE = 5 returning structure is
DEV_BROADCAST_DEVICEINTERFACE with a size of 32 bytes.
Can anyone throw any light on this?
Thanks
Duncan.
"Duncan" wrote:
[color=darkred]
> there seems to be more to this than I originally thought,
>
> Thanks for the response. Perhaps I'll take a look at the book.
>
> Duncan.
>
> "Dick Grier" wrote:
>
|
|
|
|
|