第一个参数是API函数 CreateFile 函数返回的打开的文件句柄使用OPEN_ALWAYS标志来打开文件就可以了,如下:HANDLE   hFile;   
int   iSize;   
hFile   =   CreateFile("C:\111.txt",   GENERIC_READ,   FILE_SHARE_READ,   NULL,   OPEN_ALWAYS,   FILE_ATTRIBUTE_NORMAL,NULL);   
iSize   =   GetFileSize(hFile,   NULL);   
CloseHandle(hFile);  
ShowMessage(IntToStr(iSize));

解决方案 »

  1.   

    这样先用createfile返回文件句柄,然后获得文件大小是没有问题的,关键是我用hook获得了文件的句柄,然后希望通过文件句柄返回文件名,但是在GetFilesize 时,返回为0?
      

  2.   

    "用hook获得了文件的句柄"HOOK的是API吗?哪个?writefile?
      

  3.   

    试试用CFileStatus status;CFile::GetStatus这个
      

  4.   

    to myjian:确实是hook了writefile获得的文件句柄!!to Allen_zhang:但是这个函数是通过文件得到的信息,我现在只有文件的句柄!?
      

  5.   

    获得文件大小也不一下非得用API啊
    试试普通的C函数
    ftell  / lseek
      

  6.   

    hFile 
    Specifies an open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file.以上是GetFileSize的hFile参数说明.hFile 
    Handle to the file to be written to. The file handle must have been created with GENERIC_WRITE access to the file. 
    Windows NT: 
    For asynchronous write operations, hFile can be any handle opened with the FILE_FLAG_OVERLAPPED flag by the CreateFile function, or a socket handle returned by thesocket oraccept functions. 
    Windows 95: 
    For asynchronous write operations, hFile can be a communications resource, mailslot, or named pipe handle opened with the FILE_FLAG_OVERLAPPED flag by CreateFile, or a socket handle returned by the socket or accept functions. Windows 95 does not support asynchronous write operations on disk files. 以上是WriteFile的hFile参数说明.而你HOOK得到的句柄,应该就是createfile用GENERIC_WRITE打开的....这一切看起来没什么问题呀...?建议在调用GetFileSize后再GetLastError一下,看看到底是什么原因.
      

  7.   

    delphi中的GetFileSize提示错误类型不匹配,传的参数就是String类型的啊