使用哪个代码片段来处理 USB 设备插入?
Which code fragment to use to handle USB device insertion?
应用程序可以使用 RegisterDeviceNotification function to register to receive notification messages from the system. This example 展示了如何为设备接口注册事件通知,这些接口是接口 class 的成员,其 GUID 被传递给函数。
在此示例中,我应该使用哪个代码片段来处理 USB 设备插入消息?
搜索 DBT_DEVICEARRIVAL: 这是处理 USB 设备插入消息的地方。
case WM_DEVICECHANGE:
{
//
// This is the actual message from the interface via Windows messaging.
// This code includes some additional decoding for this particular device type
// and some common validation checks.
//
// Note that not all devices utilize these optional parameters in the same
// way. Refer to the extended information for your particular device type
// specified by your GUID.
//
PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
TCHAR strBuff[256];
// Output some messages to the window.
switch (wParam)
{
case DBT_DEVICEARRIVAL:
msgCount++;
StringCchPrintf(
strBuff, 256,
TEXT("Message %d: DBT_DEVICEARRIVAL\n"), msgCount);
break;
应用程序可以使用 RegisterDeviceNotification function to register to receive notification messages from the system. This example 展示了如何为设备接口注册事件通知,这些接口是接口 class 的成员,其 GUID 被传递给函数。
在此示例中,我应该使用哪个代码片段来处理 USB 设备插入消息?
搜索 DBT_DEVICEARRIVAL: 这是处理 USB 设备插入消息的地方。
case WM_DEVICECHANGE:
{
//
// This is the actual message from the interface via Windows messaging.
// This code includes some additional decoding for this particular device type
// and some common validation checks.
//
// Note that not all devices utilize these optional parameters in the same
// way. Refer to the extended information for your particular device type
// specified by your GUID.
//
PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
TCHAR strBuff[256];
// Output some messages to the window.
switch (wParam)
{
case DBT_DEVICEARRIVAL:
msgCount++;
StringCchPrintf(
strBuff, 256,
TEXT("Message %d: DBT_DEVICEARRIVAL\n"), msgCount);
break;