GetFileInformationByHandle的参数问题 ( 积分: 100 )

  • 主题发起人 主题发起人 yongdongdefeng
  • 开始时间 开始时间
Y

yongdongdefeng

Unregistered / Unconfirmed
GUEST, unregistred user!
请教调用GetFileInformationByHandle函数后,<br>返回的By_Handle_File_Information结构中nFileIndexHigh和nFileIndexLow<br>唯一的标识一个文件。<br>如何根据这个标识获取对应的文件呢?
 
nFileIndexHigh&nbsp;<br>High-order&nbsp;part&nbsp;of&nbsp;a&nbsp;unique&nbsp;identifier&nbsp;that&nbsp;is&nbsp;associated&nbsp;with&nbsp;a&nbsp;file.&nbsp;For&nbsp;more&nbsp;information,&nbsp;see&nbsp;nFileIndexLow.&nbsp;<br>nFileIndexLow&nbsp;<br>Low-order&nbsp;part&nbsp;of&nbsp;a&nbsp;unique&nbsp;identifier&nbsp;that&nbsp;is&nbsp;associated&nbsp;with&nbsp;a&nbsp;file.&nbsp;<br>This&nbsp;value&nbsp;is&nbsp;useful&nbsp;only&nbsp;while&nbsp;the&nbsp;file&nbsp;is&nbsp;open&nbsp;by&nbsp;at&nbsp;least&nbsp;one&nbsp;process.&nbsp;If&nbsp;no&nbsp;processes&nbsp;have&nbsp;it&nbsp;open,&nbsp;the&nbsp;index&nbsp;may&nbsp;change&nbsp;the&nbsp;next&nbsp;time&nbsp;the&nbsp;file&nbsp;is&nbsp;opened.&nbsp;<br><br>The&nbsp;identifier&nbsp;(low&nbsp;and&nbsp;high&nbsp;parts)&nbsp;and&nbsp;the&nbsp;volume&nbsp;serial&nbsp;number&nbsp;that&nbsp;uniquely&nbsp;identify&nbsp;a&nbsp;file&nbsp;on&nbsp;a&nbsp;single&nbsp;computer.&nbsp;To&nbsp;determine&nbsp;whether&nbsp;two&nbsp;open&nbsp;handles&nbsp;represent&nbsp;the&nbsp;same&nbsp;file,&nbsp;combine&nbsp;this&nbsp;identifier&nbsp;and&nbsp;the&nbsp;volume&nbsp;serial&nbsp;number&nbsp;for&nbsp;each&nbsp;file&nbsp;and&nbsp;compare&nbsp;them.<br><br><br>这个参数是临时的
 
或者换一个,如何根据文件句柄获取文件名称(全路径)
 
谢谢&lt;0桁骀&gt;,我也看到,说是每次打开文件时,都会从新分配一个ID,但如果一个文件被打开,别的程序打开相同的文件,则ID相同!那有没有办法根据文件句柄获取文件名称呢。
 
如果是200分就好了:)<br><br>上次有人问了这个问题,从handle获得文件名,帖子忘记了,代码如下<br><br>uses&nbsp;uses&nbsp;psapi,&nbsp;StrUtils;<br><br><br>function&nbsp;GetFileNameFromHandle(hFile:THandle):String;<br>Const<br>BUFSIZE=512;<br>Var<br>pszFilename:Array[0..BUFSIZE+1]&nbsp;of&nbsp;CHAR;<br>hFileMap:THandle;<br>//dwFileSizeHi:DWORD;<br>//dwFileSizeLo:DWORD;<br>pMem:Pointer;<br>szTemp:Array[0..MAX_PATH-1]&nbsp;of&nbsp;CHAR;<br>p:PChar;<br>Str:String;<br>begin<br>Result:='';<br>FillChar(pszFilename,sizeof(pszFilename),0);<br>hFileMap&nbsp;:=&nbsp;CreateFileMapping(hFile,<br>nil,<br>PAGE_READONLY,<br>0,<br>1,<br>nil);<br><br>if&nbsp;hFileMap&amp;lt;&amp;gt;INVALID_HANDLE_VALUE&nbsp;then<br>begin<br>pMem&nbsp;:=&nbsp;MapViewOfFile(hFileMap,&nbsp;FILE_MAP_READ,&nbsp;0,&nbsp;0,&nbsp;1);<br>if&nbsp;Assigned(pMem)&nbsp;then<br>begin<br>if&nbsp;GetMappedFileName&nbsp;(GetCurrentProcess,<br>pMem,<br>pszFilename,<br>MAX_PATH)&amp;lt;&amp;gt;0&nbsp;then<br>begin<br>Str:=StrPas(pszFileName);<br>if&nbsp;GetLogicalDriveStrings(BUFSIZE-1,&nbsp;@pszFileName)&amp;lt;&amp;gt;0&nbsp;then<br>begin<br>p:=@pszFileName;<br>Repeat<br>Inc(p,2);<br>p^:=#0;<br>Dec(p,2);<br>FillChar(szTemp,sizeof(szTemp),0);<br>if&nbsp;QueryDosDevice(p,&nbsp;@szTemp,&nbsp;MAX_PATH)&amp;lt;&amp;gt;0&nbsp;then<br>begin<br>if&nbsp;AnsiPos(szTemp,Str)&amp;lt;&amp;gt;0&nbsp;then<br>begin<br>Result&nbsp;:=&nbsp;p+AnsiReplaceStr(Str,szTemp,'');<br>Exit;<br>end;<br>end;<br>Inc(p,4);<br>Until&nbsp;p^=#0;<br>end;<br>end;<br>UnmapViewOfFile(pMem);<br>end;<br>CloseHandle(hFileMap);<br>end;<br>end;
 
这样也行,不服不行啊,多谢
 
接受答案了.
 
后退
顶部