首页 > 代码库 > U盘直接读写(今天用到了)
U盘直接读写(今天用到了)
#ifndef INVALID_SET_FILE_POINTER#define INVALID_SET_FILE_POINTER (DWORD)-1#endif#define FILE_BEGIN 0#define FILE_CURRENT 1#define FILE_END 2HANDLE m_hDisk = NULL;bool Open(char *vol){ char szDrive[10]; sprintf(szDrive, "\\\\.\\%c:", vol[0]); //sprintf(szDrive, "\\\\.\\scsi1:"); m_hDisk = ::CreateFile( szDrive, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); DWORD dwError = ::GetLastError(); return m_hDisk != INVALID_HANDLE_VALUE;}void Close(){ if (m_hDisk != INVALID_HANDLE_VALUE) ::CloseHandle(m_hDisk);}bool ReadSector (DWORD sector, char *Buffer, int sectorSize){ DWORD read = 0; if (::SetFilePointer(m_hDisk, sector, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) return false; if (!::ReadFile(m_hDisk, Buffer, sectorSize, &read, NULL)) return false; return true;}bool WriteSector(DWORD sector, char *Buffer, int sectorSize){ DWORD wrote = 0; if (::SetFilePointer(m_hDisk, sector, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) return false; if (!::WriteFile(m_hDisk, Buffer, sectorSize, &wrote, NULL)) return false; return true;}
U盘直接读写(今天用到了)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。