开发者

Unable to Open Handle

Please see the code:

int main(int argc,LPTSTR argv[])
{
HANDLE hinFile;
BOOL check;
PLARGE_INTEGER file_size;
hinFile=CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hinFile==INVALID_HANDLE_VALUE)
    {printf("INVALID_开发者_开发问答HANDLE_VALUE\nFile Does Not Exist");exit(0);}
else{
    check=GetFileSizeEx(hinFile,file_size);
    printf("The Size of File is %d",file_size);
}
return 0;
}

Now, in the above program whether i try to open a file in directory of the Executable or i specify the path as command line arguments, the only output i get is:

INVALID_HANDLE_VALUE\nFile Does Not Exist

Please Explain why this is happening?


I modified a little your code to make it work.

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

int _tmain(int argc, TCHAR *argv[])
{
HANDLE hinFile;
BOOL check;
LARGE_INTEGER li;
PLARGE_INTEGER file_size;

file_size=&li;

hinFile=CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hinFile==INVALID_HANDLE_VALUE)
{
    printf("INVALID_HANDLE_VALUE\nFile Does Not Exist");
}
else
{
    check = GetFileSizeEx(hinFile,file_size);
    printf("The Size of File is %I64d",file_size->QuadPart);
}
return 0;
}

I tested with Visual Studio 2005 (Version 8.0).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜