调研USB弹出,记录结果:
bool CUSBControl::RemoveUSB(CString csDisk)
{
HANDLE hDevice; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results
DWORD dwError;
CString csVolume;
int nPos = csDisk.Find('\\');//csDisk like "H:\"
if ( -1 != nPos )
{
csDisk = csDisk.Left(nPos);
}
csVolume.Format(L"\\\\.\\%s", csDisk);
// Open the volume
hDevice = CreateFile(csVolume, // drive to open
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // don't copy any file's attributes
if (hDevice == INVALID_HANDLE_VALUE) // can't open the drive
{
dwError = GetLastError();
return FALSE;
}
//Dismount