第一个参数是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));
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));
试试普通的C函数
ftell / lseek
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一下,看看到底是什么原因.