当前位置: 首页>>代码示例>>C++>>正文


C++ GetFileInformationByHandle函数代码示例

本文整理汇总了C++中GetFileInformationByHandle函数的典型用法代码示例。如果您正苦于以下问题:C++ GetFileInformationByHandle函数的具体用法?C++ GetFileInformationByHandle怎么用?C++ GetFileInformationByHandle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetFileInformationByHandle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: kludge_isKernel32Dll

// check if a file handle is for kernel32.dll
static bool kludge_isKernel32Dll(HANDLE fileHandle, std::string &kernel32Name) {
    static DWORD IndxHigh, IndxLow;
    static bool firstTime = true;
    BY_HANDLE_FILE_INFORMATION info;
    static std::string kernel32Name_;

    if (firstTime) {
       HANDLE kernel32H;
       firstTime = false;
       char sysRootDir[MAX_PATH+1];
       if (GetSystemDirectory(sysRootDir, MAX_PATH) == 0)
          assert(0);
       kernel32Name_ = std::string(sysRootDir) + "\\kernel32.dll";
       kernel32H = CreateFile(kernel32Name_.c_str(), GENERIC_READ, 
                              FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
       assert(kernel32H);
       if (!GetFileInformationByHandle(kernel32H, &info)) {
          printSysError(GetLastError());
          assert(0);
       }
       IndxHigh = info.nFileIndexHigh;
       IndxLow = info.nFileIndexLow;
       CloseHandle(kernel32H);
    }

    if (!GetFileInformationByHandle(fileHandle, &info))
       return false;

    if (info.nFileIndexHigh==IndxHigh && info.nFileIndexLow==IndxLow) {
      kernel32Name = kernel32Name_;
      return true;
    }
    return false;
}
开发者ID:hira-a,项目名称:dyninst,代码行数:35,代码来源:pdwinnt.C

示例2: CreateFileA

bool LuaProxy::Misc::isSamePath(const std::string first, const std::string second) 
{
    HANDLE hFileFirst = CreateFileA(first.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
    if (hFileFirst == INVALID_HANDLE_VALUE) return false;
    HANDLE hFileSecond = CreateFileA(second.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
    if (hFileSecond == INVALID_HANDLE_VALUE) {
        CloseHandle(hFileFirst);
        return false;
    }

    BY_HANDLE_FILE_INFORMATION fInfoFirst = { 0 };
    BY_HANDLE_FILE_INFORMATION fInfoSecond = { 0 };
    BOOL success = GetFileInformationByHandle(hFileFirst, &fInfoFirst);
    success = success && GetFileInformationByHandle(hFileSecond, &fInfoSecond);
    if (!success) {
        CloseHandle(hFileFirst);
        CloseHandle(hFileSecond);
        return false;
    }

    bool isSame = fInfoFirst.dwVolumeSerialNumber == fInfoSecond.dwVolumeSerialNumber &&
        fInfoFirst.nFileIndexLow == fInfoSecond.nFileIndexLow &&
        fInfoFirst.nFileIndexHigh == fInfoSecond.nFileIndexHigh;

    CloseHandle(hFileFirst);
    CloseHandle(hFileSecond);
    
    return isSame;
}
开发者ID:ifzz,项目名称:LunaDLL,代码行数:29,代码来源:LuaProxyGlobalFuncMisc.cpp

示例3: IsSame

// Code adapted from http://stackoverflow.com/questions/562701/best-way-to-determine-if-two-path-reference-to-same-file-in-c-c/562830#562830
// Determine if 2 paths point ot the same file...
bool IsSame(const WCHAR *path1, const WCHAR *path2)
{
    bool isSame = false, needFallback = true;
    HANDLE handle1 = CreateFile(path1, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
    HANDLE handle2 = CreateFile(path2, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

    if (handle1 != INVALID_HANDLE_VALUE && handle2 != INVALID_HANDLE_VALUE) {
        BY_HANDLE_FILE_INFORMATION fi1, fi2;
        if (GetFileInformationByHandle(handle1, &fi1) && GetFileInformationByHandle(handle2, &fi2)) {
            isSame = fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber &&
                     fi1.nFileIndexHigh == fi2.nFileIndexHigh &&
                     fi1.nFileIndexLow == fi2.nFileIndexLow;
            needFallback = false;
        }
    }

    CloseHandle(handle1);
    CloseHandle(handle2);

    if (!needFallback)
        return isSame;

    ScopedMem<WCHAR> npath1(Normalize(path1));
    ScopedMem<WCHAR> npath2(Normalize(path2));
    // consider the files different, if their paths can't be normalized
    if (!npath1 || !npath2)
        return false;
    return str::EqI(npath1, npath2);
}
开发者ID:DavidWiberg,项目名称:sumatrapdf,代码行数:31,代码来源:FileUtil.cpp

示例4: CheckFiles

int CheckFiles(HANDLE hFile1, HANDLE hFile2)
{

	BY_HANDLE_FILE_INFORMATION info1;
	BY_HANDLE_FILE_INFORMATION info2;
    BOOL r1 = GetFileInformationByHandle(hFile1, &info1);
    BOOL r2 = GetFileInformationByHandle(hFile2, &info2);

	if (!r1 && !r2) {
		return 0;
	}
	else if (r1 && !r2) {
		return 1;
	}
	else if (!r1 && r2) {
		return -1;
	}

	if (info1.dwVolumeSerialNumber != info2.dwVolumeSerialNumber) {
		return info1.dwVolumeSerialNumber - info2.dwVolumeSerialNumber;
	}

	if (info1.nFileIndexHigh != info2.nFileIndexHigh) {
		return info1.nFileIndexHigh - info2.nFileIndexHigh;
	}
	return info1.nFileIndexLow - info2.nFileIndexLow;
}
开发者ID:holy-shit,项目名称:fallout-skyrim-optimizer,代码行数:27,代码来源:miscfuncs.cpp

示例5: same_stream

/* Return non-zero if F1 and F2 are 2 streams representing the same
   file or pipe or device.  */
int
same_stream (FILE *f1, FILE *f2)
{
  HANDLE fh1 = (HANDLE)_get_osfhandle (fileno (f1));
  HANDLE fh2 = (HANDLE)_get_osfhandle (fileno (f2));

  /* Invalid file descriptors get treated as different streams.  */
  if (fh1 && fh1 != INVALID_HANDLE_VALUE
      && fh2 && fh2 != INVALID_HANDLE_VALUE)
    {
      if (fh1 == fh2)
        return 1;
      else
        {
          DWORD ftyp1 = GetFileType (fh1), ftyp2 = GetFileType (fh2);

          if (ftyp1 != ftyp2
              || ftyp1 == FILE_TYPE_UNKNOWN || ftyp2 == FILE_TYPE_UNKNOWN)
            return 0;
          else if (ftyp1 == FILE_TYPE_CHAR)
            {
              /* For character devices, check if they both refer to a
                 console.  This loses if both handles refer to the
                 null device (FIXME!), but in that case we don't care
                 in the context of Make.  */
              DWORD conmode1, conmode2;

              /* Each process on Windows can have at most 1 console,
                 so if both handles are for the console device, they
                 are the same.  We also compare the console mode to
                 distinguish between stdin and stdout/stderr.  */
              if (GetConsoleMode (fh1, &conmode1)
                  && GetConsoleMode (fh2, &conmode2)
                  && conmode1 == conmode2)
                return 1;
            }
          else
            {
              /* For disk files and pipes, compare their unique
                 attributes.  */
              BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2;

              /* Pipes get zero in the volume serial number, but do
                 appear to have meaningful information in file index
                 attributes.  We test file attributes as well, for a
                 good measure.  */
              if (GetFileInformationByHandle (fh1, &bhfi1)
                  && GetFileInformationByHandle (fh2, &bhfi2))
                return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber
                        && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow
                        && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh
                        && bhfi1.dwFileAttributes == bhfi2.dwFileAttributes);
            }
        }
    }
  return 0;
}
开发者ID:mirror,项目名称:make,代码行数:59,代码来源:posixfcn.c

示例6: tr_sys_path_is_same

bool
tr_sys_path_is_same (const char  * path1,
                     const char  * path2,
                     tr_error   ** error)
{
  bool ret = false;
  wchar_t * wide_path1 = NULL;
  wchar_t * wide_path2 = NULL;
  HANDLE handle1 = INVALID_HANDLE_VALUE;
  HANDLE handle2 = INVALID_HANDLE_VALUE;
  BY_HANDLE_FILE_INFORMATION fi1, fi2;

  assert (path1 != NULL);
  assert (path2 != NULL);

  wide_path1 = tr_win32_utf8_to_native (path1, -1);
  if (wide_path1 == NULL)
    goto fail;

  wide_path2 = tr_win32_utf8_to_native (path2, -1);
  if (wide_path2 == NULL)
    goto fail;

  handle1 = CreateFileW (wide_path1, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
  if (handle1 == INVALID_HANDLE_VALUE)
    goto fail;

  handle2 = CreateFileW (wide_path2, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
  if (handle2 == INVALID_HANDLE_VALUE)
    goto fail;

  /* TODO: Use GetFileInformationByHandleEx on >= Server 2012 */

  if (!GetFileInformationByHandle (handle1, &fi1) || !GetFileInformationByHandle (handle2, &fi2))
    goto fail;

  ret = fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber &&
        fi1.nFileIndexHigh == fi2.nFileIndexHigh &&
        fi1.nFileIndexLow  == fi2.nFileIndexLow;

  goto cleanup;

fail:
  set_system_error_if_file_found (error, GetLastError ());

cleanup:
  CloseHandle (handle2);
  CloseHandle (handle1);

  tr_free (wide_path2);
  tr_free (wide_path1);

  return ret;
}
开发者ID:Elbandi,项目名称:transmission,代码行数:54,代码来源:file-win32.c

示例7: GetStatByHandle

static bool GetStatByHandle(TSystemFStat& fs, FHANDLE f) {
#ifdef _win_
    return GetFileInformationByHandle(f, &fs);
#else
    return !fstat(f, &fs);
#endif
}
开发者ID:Frankie-666,项目名称:tomita-parser,代码行数:7,代码来源:fstat.cpp

示例8: fci_get_open_info

static INT_PTR CDECL fci_get_open_info( char *name, USHORT *date, USHORT *time,
                                        USHORT *attribs, int *err, void *ptr )
{
    HANDLE handle;
    BY_HANDLE_FILE_INFORMATION info;
    WCHAR *p, *nameW = strdupAtoW( CP_UTF8, name );

    handle = CreateFileW( nameW, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
                          NULL, OPEN_EXISTING, 0, NULL );
    if (handle == INVALID_HANDLE_VALUE)
    {
        *err = GetLastError();
        WINE_ERR( "failed to open %s: error %u\n", wine_dbgstr_w(nameW), *err );
        cab_free( nameW );
        return -1;
    }
    if (!GetFileInformationByHandle( handle, &info ))
    {
        *err = GetLastError();
        CloseHandle( handle );
        cab_free( nameW );
        return -1;
    }
    FileTimeToDosDateTime( &info.ftLastWriteTime, date, time );
    *attribs = info.dwFileAttributes & (_A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH);
    for (p = nameW; *p; p++) if (*p >= 0x80) break;
    if (*p) *attribs |= _A_NAME_IS_UTF;
    cab_free( nameW );
    return (INT_PTR)handle;
}
开发者ID:Kelimion,项目名称:wine,代码行数:30,代码来源:cabarc.c

示例9: win_get_inodes

/**
 * Get two values that (together with the device number), uniquely
 * identify a file. Taken together these values create the windows
 * equivalent of UNIX inodes. If this fails for any reason a 0 is
 * returned, otherwise a 1 is returned. On failure only the st_rdev
 * value is set to zero, normally the st_ino (if this is the result
 * of a call to stat(), may have a sensible value).
 */
int win_get_inodes( const char *fns, ino_t *st_ino, dev_t *st_rdev )
{
    HANDLE fh;
    BY_HANDLE_FILE_INFORMATION info;
    DWORD error;
    int result = 1;

    /* Open file, use FILE_SHARE_READ and FILE_SHARE_WRITE as this
     * seems to be needed for win98 (but not for XP) */
    fh = CreateFile( fns, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
                     NULL, OPEN_EXISTING, 0, NULL );
    if ( fh != INVALID_HANDLE_VALUE ) {

        if ( GetFileInformationByHandle( fh, &info ) ) {
            *st_ino = info.nFileIndexLow;
            *st_rdev = info.nFileIndexHigh;
        }
        else {
            *st_rdev = 0;
            result = 0;
        }
        CloseHandle( fh );
    }
    else {
        *st_rdev = 0;
        result = 0;
    }
    return result;
}
开发者ID:astrobuff,项目名称:starlink,代码行数:37,代码来源:win_fixups.c

示例10: rLock

__int64 FileReader::GetFileSize()
{
  CAutoLockFR rLock (&m_accessLock);

	if (m_hFile == INVALID_HANDLE_VALUE) 
  {
    //LogDebug("FileReader::GetFileSize() no open file");
		return -1;
	}
  
  BY_HANDLE_FILE_INFORMATION fileinfo;
		
  //fill the structure with info regarding the file
  if (GetFileInformationByHandle(m_hFile, &fileinfo))
  {	  
    //Extract the file size info
  	LARGE_INTEGER li;
  	li.LowPart  = fileinfo.nFileSizeLow;
  	li.HighPart = fileinfo.nFileSizeHigh;
  	
	  return li.QuadPart;
  }
  
  HRESULT lastErr = HRESULT_FROM_WIN32(GetLastError());	  
	LogDebug("FileReader::GetFileSize() failed. Error 0x%x, %ws, filename = %ws", lastErr, HresultToCString(lastErr), m_pFileName);    
  return -1;
}
开发者ID:MediaPortal,项目名称:MediaPortal-1,代码行数:27,代码来源:FileReader.cpp

示例11: filefind_index_number_of_links_helper

static int filefind_index_number_of_links_helper(lua_State* L, struct FileFindInfo* info) {
#if defined(_WIN32)
	HANDLE handle;
	BY_HANDLE_FILE_INFORMATION fileInformation;

	char fullPath[MAX_PATH];
	strcpy(fullPath, info->path);
	strcat(fullPath, info->fd.cFileName);

	handle = CreateFile(fullPath, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (handle == INVALID_HANDLE_VALUE) {
		lua_pushnumber(L, 0);
		return 1;
	}
	if (GetFileInformationByHandle(handle, &fileInformation) == FALSE) {
		CloseHandle(handle);
		lua_pushnumber(L, 0);
		return 1;
	}
	CloseHandle(handle);

	lua_pushnumber(L, fileInformation.nNumberOfLinks);
#else
	lua_pushnumber(L, 0);
#endif
	return 1;
}
开发者ID:arventwei,项目名称:jamplus,代码行数:27,代码来源:filefind.c

示例12: Stat

bool CRawFile::Stat( struct stat *pFileStats ) const
{
#ifdef _WIN32
    BY_HANDLE_FILE_INFORMATION info;

    if (!GetFileInformationByHandle( m_file, &info ))
        return false;

    pFileStats->st_size = info.nFileSizeLow;
    pFileStats->st_dev = info.nFileIndexLow;
    pFileStats->st_atime = info.ftLastAccessTime.dwLowDateTime;
    pFileStats->st_ctime = info.ftCreationTime.dwLowDateTime;
    pFileStats->st_mtime = info.ftLastWriteTime.dwLowDateTime;
    pFileStats->st_dev = info.dwVolumeSerialNumber;
    pFileStats->st_mode = 0;
    pFileStats->st_nlink = (unsigned short)info.nNumberOfLinks;
    pFileStats->st_rdev = 0;
    pFileStats->st_gid = 0;
    return true;
#elif __linux
    return fstat( fileno( m_file ), pFileStats ) != 0;
#else
    return false;
#endif //OS DEPENDANT CODE
}
开发者ID:quiret,项目名称:magic-txd,代码行数:25,代码来源:CFileSystem.stream.raw.cpp

示例13: IStream_fnStat

/*************************************************************************
 * IStream_fnStat
 */
static HRESULT WINAPI IStream_fnStat(IStream *iface, STATSTG* lpStat,
                                     DWORD grfStatFlag)
{
    ISHFileStream *This = impl_from_IStream(iface);
    BY_HANDLE_FILE_INFORMATION fi;

    TRACE("(%p,%p,%d)\n", This, lpStat, grfStatFlag);

    if (!grfStatFlag)
        return STG_E_INVALIDPOINTER;

    memset(&fi, 0, sizeof(fi));
    GetFileInformationByHandle(This->hFile, &fi);

    if (grfStatFlag & STATFLAG_NONAME)
      lpStat->pwcsName = NULL;
    else
      lpStat->pwcsName = StrDupW(This->lpszPath);
    lpStat->type = This->type;
    lpStat->cbSize.u.LowPart = fi.nFileSizeLow;
    lpStat->cbSize.u.HighPart = fi.nFileSizeHigh;
    lpStat->mtime = fi.ftLastWriteTime;
    lpStat->ctime = fi.ftCreationTime;
    lpStat->atime = fi.ftLastAccessTime;
    lpStat->grfMode = This->dwMode;
    lpStat->grfLocksSupported = 0;
    memcpy(&lpStat->clsid, &IID_IStream, sizeof(CLSID));
    lpStat->grfStateBits = This->grfStateBits;
    lpStat->reserved = 0;

    return S_OK;
}
开发者ID:GYGit,项目名称:reactos,代码行数:35,代码来源:istream.c

示例14: GetPlatformFileInfo

    bool GetPlatformFileInfo(PlatformFile file, PlatformFileInfo* info)
    {
        ThreadRestrictions::AssertIOAllowed();
        if(!info)
        {
            return false;
        }

        BY_HANDLE_FILE_INFORMATION file_info;
        if(GetFileInformationByHandle(file, &file_info) == 0)
        {
            return false;
        }

        LARGE_INTEGER size;
        size.HighPart = file_info.nFileSizeHigh;
        size.LowPart = file_info.nFileSizeLow;
        info->size = size.QuadPart;
        info->is_directory =
            (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
        info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime);
        info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime);
        info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime);
        return true;
    }
开发者ID:abyvaltsev,项目名称:putty-nd3.x,代码行数:25,代码来源:platform_file.cpp

示例15: CreateFile

/**
 * stat a file and return the appropriate object
 * This would better be done on an open file handle
 */
int file_metadata_t::stat(const tstring &fn,
			  file_metadata_t *m,
			  class display &ocb)
{
  struct __stat64 sb;
  if (::TSTAT(fn.c_str(),&sb)) 
  {
    ocb.error_filename(fn,"%s",strerror(errno));
    return -1;
  }
  m->fileid.dev = sb.st_dev;
#ifdef _WIN32
  BY_HANDLE_FILE_INFORMATION fileinfo;
  HANDLE filehandle = CreateFile(fn.c_str(),
				 0,   // desired access
				 FILE_SHARE_READ,
				 NULL,  
				 OPEN_EXISTING,
				 (FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS),
				 NULL);
  // RBF - Error check CreateFile
  (void)GetFileInformationByHandle(filehandle, &fileinfo);
  CloseHandle(filehandle);
  m->fileid.ino = (((uint64_t)fileinfo.nFileIndexHigh)<<32) | (fileinfo.nFileIndexLow);
#else
  m->fileid.ino = sb.st_ino;
#endif
  m->nlink      = sb.st_nlink;
  m->size       = sb.st_size;
  m->ctime      = sb.st_ctime;
  m->mtime      = sb.st_mtime;
  m->atime      = sb.st_atime;

  return 0;
}
开发者ID:henry-bennett,项目名称:hashdeep,代码行数:39,代码来源:dig.cpp


注:本文中的GetFileInformationByHandle函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。