Obtain a USB device

Source: Internet
Author: User
Tags define function

1. Add message ing

Message ing
Begin_message_map (constnetcndlg, cdialog)
// {Afx_msg_map (constnetcndlg)
On_wm_paint ()
On_wm_querydragicon ()
...
On_wm_devicechange ()
//} Afx_msg_map

Declare the message response function:
Afx_msg bool ondevicechange (uint neventtype, DWORD dwdata );

Define function content:

Bool constnetcndlg: ondevicechange (uint neventtype, DWORD dwdata)
{
Dev_broadcast_deviceinterface * DBD = (dev_broadcast_deviceinterface *) dwdata;

// Information matching, such as guid

// Process events.
Switch (neventtype)
{
Case dbt_deviceremovecomplete:
MessageBox ("Remove USB ");
Break;
Case dbt_devicearrival:
MessageBox ("USB found ");
Break;
Default:
Break;
}

Return true;

}

2. register the device (add it to oninitdialog)

Dev_broadcast_deviceinterface devint;
Memset (& devint, 0, sizeof (dev_broadcast_deviceinterface ));
Devint. dbcc_size = sizeof (dev_broadcast_deviceinterface );
Devint. dbcc_devicetype = dbt_devtyp_deviceinterface;

Devint. dbcc_classguid = {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed }};
Registerdevicenotificationthis-> getsafehwnd (), & devint, device_policy_window_handle );

PS: only when the device is registered can ondevicechange obtain detailed information. Otherwise, all the received neventtype parameters are 0007, and dwdata has no data. [Drinking wine] http://blog.const.net.cn/a/412.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.