USB Mass Storage 设备,如何只允许打开一次?

of123 2011-08-31 04:17:28
USB MSD 设备,得到路径后用 CreateFile 打开。

在同一个应用中,如何限制同一个设备只能打开一次。即已经打开过在就不能再 CreateFile,除非 CloseHandle。

除了程序中记录已打开的路径外,还有更好的方法吗?例如设置 CreateFile 的哪些参数?
...全文
212 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
danxuezx 2011-09-01
  • 打赏
  • 举报
回复
dwShareMode [in]
The requested sharing mode of the file or device, which can be read, write, both, delete, all of these, or none (refer to the following table). Access requests to attributes or extended attributes are not affected by this flag.

If this parameter is zero and CreateFile succeeds, the file or device cannot be shared and cannot be opened again until the handle to the file or device is closed. For more information, see the Remarks section

http://msdn.microsoft.com/en-us/library/aa363858(v=vs.85).aspx


Eleven 2011-09-01
  • 打赏
  • 举报
回复
[Quote=引用楼主 of123 的回复:]
USB MSD 设备,得到路径后用 CreateFile 打开。

在同一个应用中,如何限制同一个设备只能打开一次。即已经打开过在就不能再 CreateFile,除非 CloseHandle。

除了程序中记录已打开的路径外,还有更好的方法吗?例如设置 CreateFile 的哪些参数?
[/Quote]
已独占方式打开不行吗?
用户 昵称 2011-09-01
  • 打赏
  • 举报
回复
同一应用用互斥就很好了。
finrockroad 2011-09-01
  • 打赏
  • 举报
回复
用互斥方式!
sb3day 2011-08-31
  • 打赏
  • 举报
回复
CreateFile(strUsbName,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
NULL);
quwei197874 2011-08-31
  • 打赏
  • 举报
回复
用个加密狗
见习学术士 2011-08-31
  • 打赏
  • 举报
回复
CreateFile 没有参数可以限制。
你可以使用互斥对象做限制或者驱动里面做限制,

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧