createfile极不稳定?(100分)

  • 主题发起人 主题发起人 alum
  • 开始时间 开始时间
A

alum

Unregistered / Unconfirmed
GUEST, unregistred user!
一模一样的程序。<br>其中用到createfile。<br>在我机器上,百分百打开成功,再其他人的机器上却<br>失败率极高(返回句柄为65535)<br>不知道各位有无遇到这种情况?<br><br>var hRead,hWrite &nbsp;: Word ;<br><br>&nbsp;hWrite := CreateFile(sWritePath,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_WRITE Or GENERIC_READ,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_SHARE_WRITE or FILE_SHARE_READ,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0);<br><br>&nbsp;hRead := CreateFile(sReadPath,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_WRITE Or GENERIC_READ,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_SHARE_WRITE or FILE_SHARE_READ,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0);
 
都不稳定。嘻嘻。<br>
 
别人机器上没有你要打开的文件。
 
首先可以确定,存在这个文件(其实是设备),<br>但只是打开成功的几率比较低.(不稳定)
 
hWrite, hRead: WORD ? 应该是 DWORD (或 THandle)吧。敲错了?
 
用 f: File;<br>Assigned(F,'c:/1.txt');<br>Rewrite(F);<br>write(F,'');<br>closeFile(f);<br>这样的方式呢? 虽然傻点,也许会更好的。<br>
 
word/dword有影响么?
 
CreateFile 返回的是 DWORD,如果你的 hWrite, hRead 是 WORD 的话,返回的双字的高字<br>就被截掉了,有可能返回了大于 65535 的值,但又不是 invalid_handle,而你只能得到<br>65535.
 
原来如此!多谢各位!!
 
后退
顶部