Win32的C / C ++读取数据的"锁定"文件 [英] win32 C/C++ read data from a "locked" file

查看:379
本文介绍了Win32的C / C ++读取数据的"锁定"文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道如何从被另一个进程锁定的文件中读取数据?

Any idea how to read data from a file that is locked by another process?

当我尝试fopen()函数或的CreateFile()或打开文件()我得到共享冲突。

When I try fopen() or CreateFile() or OpenFile() I get sharing violation.

然而,如果我去命令提示符下,做一个C:>更blah.h我可以看到文件。因此,多在某种程度上可以读取该文件。任何想法,它是如何完成的?

Yet if I go to command prompt and do a "c:> more blah.h" I can see the file. So "more" somehow can read the file. Any idea how it accomplishes that?

谢谢!

推荐答案

的fopen是德precated和MSDN建议fopen_s但是对于启用共享心不是。

fopen is deprecated and msdn recommends fopen_s but sharing isnt enabled for that .

文件由fopen_s开_wfopen_s不共享。如果您需要
  一个文件可以共享,使用_f​​sopen,_wfsopen用适当的
  共享模式常数(例如,_SH_DENYNO用于读/写
  共享)。

Files opened by fopen_s and _wfopen_s are not sharable. If you require that a file be sharable, use _fsopen, _wfsopen with the appropriate sharing mode constant (for example, _SH_DENYNO for read/write sharing).

使用_fsopen打开文件并启用一个标志共享(_SH_DENYNO)给共享访问。

use _fsopen to open the file and enable a flag to share ( _SH_DENYNO ) to give sharing access.

fsopen

这篇关于Win32的C / C ++读取数据的"锁定"文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆