在VC++发布没有几个理,在这里试试。有关CreateFile().有谁回答对了的给绝对加分(50分)

  • 主题发起人 主题发起人 tangzwei
  • 开始时间 开始时间
T

tangzwei

Unregistered / Unconfirmed
GUEST, unregistred user!
在VC++6.0中<br>出现一怪问题,明明已经创建了这个文件,可就是得不到这个文件的句柄。<br>下段代码的结果是:文件创建了,newhandle=INVALID_HANDLE_VALUE ,WriteBytes=0<br>请各位富翁看看,能说出问题,马上给分。<br><br> CHAR filename[200] ;<br> DWORD WriteBytes;<br> HANDLE newhandle ;<br> LPTSTR filestr ;<br><br> filestr="E://MNaa.txt" ;<br> //lstrcpy(filename,"E://MNaa.txt") ;<br><br> newhandle=CreateFile(filestr,GENERIC_WRITE, &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_SHARE_READ, &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_ALWAYS,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_ATTRIBUTE_ARCHIVE, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br> <br> if (newhandle=INVALID_HANDLE_VALUE) <br> {<br> &nbsp; WriteBytes=GetLastError();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_sprocess.Format( TEXT(" faile &nbsp;%d "),WriteBytes);<br> }<br> else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_sprocess=" ok &nbsp;";<br> UpdateData(false) ;
 
如果E:/Mnaa.txt不存在,应将OPEN_ALWAYS换成CREATE_ALWAYS.<br>如果e:/Mnna.txt的属性不是Archive,应将FILE_ATTRIBUTE_ARCHIVE换成FILE_ATTRIBUTE_NORMAL
 
hFile = CreateFile(<br>&nbsp;FileFullName, <br>&nbsp;GENERIC_WRITE,<br>&nbsp;FILE_SHARE_READ|FILE_SHARE_WRITE, &nbsp;//不只光有READ;<br>&nbsp;0, <br>&nbsp;OPEN_EXISTING, <br>&nbsp;FILE_FLAG_SEQUENTIAL_SCAN, 0)
 
谢谢楼上的两个兄弟的参与。<br>你们说的都不是问题。<br>问题我已解决。
 
谁说几个月没人理,我不是人?<br>上次在VC版面里看到你的问题,也没仔细看就给了你一个MFC的文件创建例子。<br>谁知,您不领情,呵呵。<br><br>这次,不小心看到您的问题,仔细试了一下,老兄真是犯低级错误了。<br>if (newhandle=INVALID_HANDLE_VALUE) <br>改成:<br>if (newhandle==INVALID_HANDLE_VALUE) <br><br>我这里得到句柄没有问题。<br>呵呵,一不小心,得了两个帖子的分。老兄快给分!
 
haha,没多过去,还真是,哈哈。
 
后退
顶部