比如我有一个1G大小的文件,我不想完全读取它,只读取前面的512字节.
是用 SECURITY_ATTRIBUTES 这个结构来控制它吗?
CreateFile("R:\test.txt", FILE_READ_DATA,FILE_SHARE_READ, file,OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE,NULL);
但是编译的时候就出现了这个错误.
error C2664: “CreateFileA”: 不能将参数 4 从“SECURITY_ATTRIBUTES”转换为“LPSECURITY_ATTRIBUTES”

解决方案 »

  1.   

    显然不是,SECURITY_ATTRIBUTES是安全描述符(security descriptor);
    lpSecurityAttributes 
    A pointer to a SECURITY_ATTRIBUTES structure that contains an optional security descriptor and also determines whether or not the returned handle can be inherited by child processes. The parameter can be NULL.If the lpSecurityAttributes parameter is NULL, the handle returned by CreateFile cannot be inherited by any child processes your application may create and the object associated with the returned handle gets a default security descriptor.The bInheritHandle member of the structure specifies whether the returned handle can be inherited.The lpSecurityDescriptor member of the structure specifies a security descriptor for an object, but may also be NULL. If lpSecurityDescriptor member is NULL, the object associated with the returned handle is assigned a default security descriptor.CreateFile ignores the lpSecurityDescriptor member when opening an existing file, but continues to use the bInheritHandle member.
    ----------------------
    你要看ReadFile函数的
    BOOL WINAPI ReadFile(
      __in         HANDLE hFile,
      __out        LPVOID lpBuffer,
      __in         DWORD nNumberOfBytesToRead,
      __out_opt    LPDWORD lpNumberOfBytesRead,
      __inout_opt  LPOVERLAPPED lpOverlapped
    );
      

  2.   

    error C2664: “CreateFileA”: 不能将参数 4 从“SECURITY_ATTRIBUTES”转换为“LPSECURITY_ATTRIBUTES”
    前面是SECURITY_ATTRIBUTES,后面是指向他的指针
      

  3.   

    SECURITY_ATTRIBUTES是用来设置安全属性,一般情况下可设为NULL,使用默认安全属性
      

  4.   

    CreateFile只是打开文件  还没读呢