CloseHandle的参数是HANDLE,不是你的文件名

解决方案 »

  1.   

    CreateFile(....,OPEN_EXISTING,....)不就是用来打开文件句柄的吗?
      

  2.   

    不是吧?MSDN是这样的:那最后一个参数才是HANDLE呀,可以那个我是NULL。
    HANDLE CreateFile(
      LPCTSTR lpFileName,          // pointer to name of the file
      DWORD dwDesiredAccess,       // access (read-write) mode
      DWORD dwShareMode,           // share mode
      LPSECURITY_ATTRIBUTES lpSecurityAttributes,
                                   // pointer to security attributes
      DWORD dwCreationDisposition,  // how to create
      DWORD dwFlagsAndAttributes,  // file attributes
      HANDLE hTemplateFile         // handle to file with attributes to 
                                   // copy
    );
      

  3.   

    if ((hFile = CreateFile(szFileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE)
        MessageBox(NULL,"请先选择一个有效的文件。",TEXT("出错啦!!"),0); 
    else{CloseHandle(hFile);}
      

  4.   

    warning C4047: '=' : 'void *' differs in levels of indirection from 'int '