解决方案 »
- 刚学数据库连接,写的程序不知道为什么就是不能连接数据库。求助大家了
- 我是VC++新手,请问我想自己写一个类,比如说Line类吧,然后里面有两个点point1,point2。还有函数Draw();
- DirectShow的Grabber抓图
- 想学习ATL,大家推荐几本书
- 模拟抛硬币
- 谁有计算不规则封闭图形的周长和面积算法源程序。
- c++ primer哪里有免费的电子书下载,帮上忙的都有分,100分相送。
- ATL如何实现COM集合,比如像MFC中的CList,CArray?
- 为什么我在vs.net里头编译后的中文菜单成了乱码?
- 密码是加密的如何模拟登录 动态处理的那
- C++里面int char 各占 4、1字节 跟多字节 unicode 存储有什么关系?
- win32 系统托盘气泡提示问题。
当初有人解决了这个问题,也没人分享一下。
昨天测试的时候,直接用API,WriteFile在Win7下操作时也是不行的,然后查了下MSDN,也没有发现什么特别的。
虽然使用FSCTL_LOCK_VOLUME 之后,已经可以正常使用WriteFile了,但为什么这样呢?
突然想到,我的MSDN是2003版的,这个时候根本没有Win7之类的,所以MSDN根本不会了解到什么。
所以赶紧去查看MSDN2010,果然有发现的。
If you write directly to a volume that has a mounted file system, you must first obtain exclusive access to the volume. Otherwise, you risk causing data corruption or system instability, because your application's writes may conflict with other changes coming from the file system and leave the contents of the volume in an inconsistent state. To prevent these problems, the following changes have been made in Windows Vista and later:A write on a volume handle will succeed if the volume does not have a mounted file system, or if one of the following conditions is true:
The sectors to be written to are boot sectors.
The sectors to be written to reside outside of file system space.
You have explicitly locked or dismounted the volume by using FSCTL_LOCK_VOLUME or FSCTL_DISMOUNT_VOLUME.
The volume has no actual file system. (In other words, it has a RAW file system mounted.)上面这一段MSDN其实已经讲得很明白,在Vista及以后的系统上,要通过盘符操作已经装有文件系统的的卷,必须使用 exclusive access(独占访问),否则可能会失败。
有两种方法,一种是独占访问,即通过FSCTL_LOCK_VOLUME 来设置独占访问。(有锁,相应的也有FSCTL_UNLOCK_VOLUME 。关掉句柄也能达到同样的效果)。
另一种,通过FSCTL_DISMOUNT_VOLUME来移除其他进程对卷的访问,但是如果设置了独占访问,那么再调用FSCTL_DISMOUNT_VOLUME就会失败。