您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ CreateFileW函数代码示例

51自学网 2021-06-01 20:14:33
  C++
这篇教程C++ CreateFileW函数代码示例写得很实用,希望能帮到您。

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

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

示例1: RTR3DECL

RTR3DECL(int) RTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags){    /*     * Validate input.     */    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);    AssertPtrReturn(pObjInfo, VERR_INVALID_POINTER);    AssertMsgReturn(    enmAdditionalAttribs >= RTFSOBJATTRADD_NOTHING                    &&  enmAdditionalAttribs <= RTFSOBJATTRADD_LAST,                    ("Invalid enmAdditionalAttribs=%p/n", enmAdditionalAttribs),                    VERR_INVALID_PARAMETER);    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x/n", fFlags), VERR_INVALID_PARAMETER);    /*     * Query file info.     */    WIN32_FILE_ATTRIBUTE_DATA Data;    PRTUTF16 pwszPath;    int rc = RTStrToUtf16(pszPath, &pwszPath);    if (RT_FAILURE(rc))        return rc;    if (!GetFileAttributesExW(pwszPath, GetFileExInfoStandard, &Data))    {        /* Fallback to FindFileFirst in case of sharing violation. */        if (GetLastError() == ERROR_SHARING_VIOLATION)        {            WIN32_FIND_DATAW FindData;            HANDLE hDir = FindFirstFileW(pwszPath, &FindData);            if (hDir == INVALID_HANDLE_VALUE)            {                rc = RTErrConvertFromWin32(GetLastError());                RTUtf16Free(pwszPath);                return rc;            }            FindClose(hDir);            Data.dwFileAttributes   = FindData.dwFileAttributes;            Data.ftCreationTime     = FindData.ftCreationTime;            Data.ftLastAccessTime   = FindData.ftLastAccessTime;            Data.ftLastWriteTime    = FindData.ftLastWriteTime;            Data.nFileSizeHigh      = FindData.nFileSizeHigh;            Data.nFileSizeLow       = FindData.nFileSizeLow;        }        else        {            rc = RTErrConvertFromWin32(GetLastError());            RTUtf16Free(pwszPath);            return rc;        }    }    /*     * Getting the information for the link target is a bit annoying and     * subject to the same access violation mess as above.. :/     */    /** @todo we're too lazy wrt to error paths here... */    if (   (fFlags & RTPATH_F_FOLLOW_LINK)        && (Data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))    {        HANDLE hFinal = CreateFileW(pwszPath,                                    GENERIC_READ,                                    FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,                                    NULL,                                    OPEN_EXISTING,                                    FILE_FLAG_BACKUP_SEMANTICS,                                    NULL);        if (hFinal != INVALID_HANDLE_VALUE)        {            BY_HANDLE_FILE_INFORMATION FileData;            if (GetFileInformationByHandle(hFinal, &FileData))            {                Data.dwFileAttributes   = FileData.dwFileAttributes;                Data.ftCreationTime     = FileData.ftCreationTime;                Data.ftLastAccessTime   = FileData.ftLastAccessTime;                Data.ftLastWriteTime    = FileData.ftLastWriteTime;                Data.nFileSizeHigh      = FileData.nFileSizeHigh;                Data.nFileSizeLow       = FileData.nFileSizeLow;            }            CloseHandle(hFinal);        }        else if (GetLastError() != ERROR_SHARING_VIOLATION)        {            rc = RTErrConvertFromWin32(GetLastError());            RTUtf16Free(pwszPath);            return rc;        }    }    RTUtf16Free(pwszPath);    /*     * Setup the returned data.     */    pObjInfo->cbObject    = ((uint64_t)Data.nFileSizeHigh << 32)                          |  (uint64_t)Data.nFileSizeLow;    pObjInfo->cbAllocated = pObjInfo->cbObject;    Assert(sizeof(uint64_t) == sizeof(Data.ftCreationTime));    RTTimeSpecSetNtTime(&pObjInfo->BirthTime,         *(uint64_t *)&Data.ftCreationTime);//.........这里部分代码省略.........
开发者ID:greg100795,项目名称:virtualbox,代码行数:101,


示例2: cop_filemap_open

int cop_filemap_open(struct cop_filemap *map, const char *filename, unsigned flags){	DWORD faccess;	DWORD mapprotect;	DWORD mapaccess;	LARGE_INTEGER fsz;	LPWSTR wfn;	int fnlen;	if ((flags & COP_FILEMAP_FLAG_W) == 0) {		/* read only access */		faccess    = GENERIC_READ;		mapprotect = PAGE_READONLY;		mapaccess  = FILE_MAP_READ;	} else if ((flags & COP_FILEMAP_SHARED)) {		/* shared write access */		faccess    = GENERIC_READ | GENERIC_WRITE;		mapprotect = PAGE_READWRITE;		mapaccess  = FILE_MAP_WRITE;	} else {		/* unshared write access */		faccess    = GENERIC_READ;		mapprotect = PAGE_READONLY;		mapaccess  = FILE_MAP_COPY;	}	fnlen = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);	if (fnlen == 0)		return -1;	wfn = malloc(sizeof(*wfn) * fnlen);	if (wfn == NULL)		return -1;	if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfn, fnlen) != fnlen) {		free(wfn);		return -1;	}	map->filehandle = CreateFileW(wfn, faccess, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);	if (map->filehandle == INVALID_HANDLE_VALUE) {		free(wfn);		return -1;	}	free(wfn);	if (!GetFileSizeEx(map->filehandle, &fsz)) {		CloseHandle(map->filehandle);		return -1;	}	if (fsz.QuadPart > SIZE_MAX) {		CloseHandle(map->filehandle);		return -1;	}	map->size = (size_t)fsz.QuadPart;	map->maphandle = CreateFileMapping(map->filehandle, NULL, mapprotect, 0, 0, NULL);	if (map->maphandle == INVALID_HANDLE_VALUE) {		CloseHandle(map->filehandle);		return -1;	}	map->ptr = MapViewOfFile(map->maphandle, mapaccess, 0, 0, 0);	if (map->ptr == NULL) {		CloseHandle(map->maphandle);		CloseHandle(map->filehandle);		return -1;	}	return 0;}
开发者ID:nickappleton,项目名称:cop,代码行数:74,


示例3: shgfi_get_exe_type

static DWORD shgfi_get_exe_type(LPCWSTR szFullPath){    BOOL status = FALSE;    HANDLE hfile;    DWORD BinaryType;    IMAGE_DOS_HEADER mz_header;    IMAGE_NT_HEADERS nt;    DWORD len;    char magic[4];    status = GetBinaryTypeW (szFullPath, &BinaryType);    if (!status)        return 0;    if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)        return 0x4d5a;    hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,                         NULL, OPEN_EXISTING, 0, 0 );    if ( hfile == INVALID_HANDLE_VALUE )        return 0;    /*     * The next section is adapted from MODULE_GetBinaryType, as we need     * to examine the image header to get OS and version information. We     * know from calling GetBinaryTypeA that the image is valid and either     * an NE or PE, so much error handling can be omitted.     * Seek to the start of the file and read the header information.     */    SetFilePointer( hfile, 0, NULL, SEEK_SET );    ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );    SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );    ReadFile( hfile, magic, sizeof(magic), &len, NULL );    if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )    {        SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );        ReadFile( hfile, &nt, sizeof(nt), &len, NULL );        CloseHandle( hfile );        /* DLL files are not executable and should return 0 */        if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)            return 0;        if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)        {             return IMAGE_NT_SIGNATURE |                    (nt.OptionalHeader.MajorSubsystemVersion << 24) |                   (nt.OptionalHeader.MinorSubsystemVersion << 16);        }        return IMAGE_NT_SIGNATURE;    }    else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )    {        IMAGE_OS2_HEADER ne;        SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );        ReadFile( hfile, &ne, sizeof(ne), &len, NULL );        CloseHandle( hfile );        if (ne.ne_exetyp == 2)            return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);        return 0;    }    CloseHandle( hfile );    return 0;}
开发者ID:GYGit,项目名称:reactos,代码行数:63,


示例4: p_readlink

/* * Parts of the The p_readlink function are heavily inspired by the php  * readlink function in link_win32.c * * Copyright (c) 1999 - 2012 The PHP Group. All rights reserved. * * For details of the PHP license see http://www.php.net/license/3_01.txt */int p_readlink(const char *link, char *target, size_t target_len){	typedef DWORD (WINAPI *fpath_func)(HANDLE, LPWSTR, DWORD, DWORD);	static fpath_func pGetFinalPath = NULL;	HANDLE hFile;	DWORD dwRet;	git_win32_path link_w;	wchar_t* target_w;	int error = 0;	assert(link && target && target_len > 0);	/*	 * Try to load the pointer to pGetFinalPath dynamically, because	 * it is not available in platforms older than Vista	 */	if (pGetFinalPath == NULL) {		HMODULE module = GetModuleHandle("kernel32");		if (module != NULL)			pGetFinalPath = (fpath_func)GetProcAddress(module, "GetFinalPathNameByHandleW");		if (pGetFinalPath == NULL) {			giterr_set(GITERR_OS,				"'GetFinalPathNameByHandleW' is not available in this platform");			return -1;		}	}	git_win32_path_from_c(link_w, link);	hFile = CreateFileW(link_w,			// file to open			GENERIC_READ,			// open for reading			FILE_SHARE_READ,		// share for reading			NULL,					// default security			OPEN_EXISTING,			// existing file only			FILE_FLAG_BACKUP_SEMANTICS, // normal file			NULL);					// no attr. template	if (hFile == INVALID_HANDLE_VALUE) {		giterr_set(GITERR_OS, "Cannot open '%s' for reading", link);		return -1;	}	target_w = (wchar_t*)git__malloc(target_len * sizeof(wchar_t));	GITERR_CHECK_ALLOC(target_w);	dwRet = pGetFinalPath(hFile, target_w, (DWORD)target_len, 0x0);	if (dwRet == 0 ||		dwRet >= target_len ||		!WideCharToMultiByte(CP_UTF8, 0, target_w, -1, target,			(int)(target_len * sizeof(char)), NULL, NULL))		error = -1;	git__free(target_w);	CloseHandle(hFile);	if (error)		return error;	/* Skip first 4 characters if they are "//?/" */	if (dwRet > 4 &&		target[0] == '//' && target[1] == '//' &&		target[2] == '?' && target[3] == '//')	{		unsigned int offset = 4;		dwRet -= 4;		/* /??/UNC/ */		if (dwRet > 7 &&			target[4] == 'U' && target[5] == 'N' && target[6] == 'C')		{			offset += 2;			dwRet -= 2;			target[offset] = '//';		}		memmove(target, target + offset, dwRet);	}	target[dwRet] = '/0';	return dwRet;}
开发者ID:aep,项目名称:libgit2,代码行数:92,


示例5: ProcessSoftwareUpdateCommand

/** * Processes a software update command * * @param  argc           The number of arguments in argv * @param  argv           The arguments normally passed to updater.exe *                        argv[0] must be the path to updater.exe * @return TRUE if the update was successful. */BOOLProcessSoftwareUpdateCommand(DWORD argc, LPWSTR *argv){  BOOL result = TRUE;  if (argc < 3) {    LOG_WARN(("Not enough command line parameters specified. "              "Updating update.status."));    // We can only update update.status if argv[1] exists.  argv[1] is    // the directory where the update.status file exists.    if (argc < 2 ||         !WriteStatusFailure(argv[1],                             SERVICE_NOT_ENOUGH_COMMAND_LINE_ARGS)) {      LOG_WARN(("Could not write update.status service update failure.  (%d)",                GetLastError()));    }    return FALSE;  }  WCHAR installDir[MAX_PATH] = {L'/0'};  if (!GetInstallationDir(argc, argv, installDir)) {    LOG_WARN(("Could not get the installation directory"));    if (!WriteStatusFailure(argv[1],                            SERVICE_INSTALLDIR_ERROR)) {      LOG_WARN(("Could not write update.status for GetInstallationDir failure."));    }    return FALSE;  }  // Make sure the path to the updater to use for the update is local.  // We do this check to make sure that file locking is available for  // race condition security checks.  BOOL isLocal = FALSE;  if (!IsLocalFile(argv[0], isLocal) || !isLocal) {    LOG_WARN(("Filesystem in path %ls is not supported (%d)",              argv[0], GetLastError()));    if (!WriteStatusFailure(argv[1],                             SERVICE_UPDATER_NOT_FIXED_DRIVE)) {      LOG_WARN(("Could not write update.status service update failure.  (%d)",                GetLastError()));    }    return FALSE;  }  nsAutoHandle noWriteLock(CreateFileW(argv[0], GENERIC_READ, FILE_SHARE_READ,                                        NULL, OPEN_EXISTING, 0, NULL));  if (INVALID_HANDLE_VALUE == noWriteLock) {      LOG_WARN(("Could not set no write sharing access on file.  (%d)",                GetLastError()));    if (!WriteStatusFailure(argv[1],                             SERVICE_COULD_NOT_LOCK_UPDATER)) {      LOG_WARN(("Could not write update.status service update failure.  (%d)",                GetLastError()));    }    return FALSE;  }  // Verify that the updater.exe that we are executing is the same  // as the one in the installation directory which we are updating.  // The installation dir that we are installing to is installDir.  WCHAR installDirUpdater[MAX_PATH + 1] = {L'/0'};  wcsncpy(installDirUpdater, installDir, MAX_PATH);  if (!PathAppendSafe(installDirUpdater, L"updater.exe")) {    LOG_WARN(("Install directory updater could not be determined."));    result = FALSE;  }  BOOL updaterIsCorrect;  if (result && !VerifySameFiles(argv[0], installDirUpdater,                                  updaterIsCorrect)) {    LOG_WARN(("Error checking if the updaters are the same./n"              "Path 1: %ls/nPath 2: %ls", argv[0], installDirUpdater));    result = FALSE;  }  if (result && !updaterIsCorrect) {    LOG_WARN(("The updaters do not match, udpater will not run."));     result = FALSE;  }  if (result) {    LOG(("updater.exe was compared successfully to the installation directory"         " updater.exe."));  } else {    if (!WriteStatusFailure(argv[1],                             SERVICE_UPDATER_COMPARE_ERROR)) {      LOG_WARN(("Could not write update.status updater compare failure."));    }    return FALSE;  }  // Check to make sure the udpater.exe module has the unique updater identity.//.........这里部分代码省略.........
开发者ID:AshishNamdev,项目名称:mozilla-central,代码行数:101,


示例6: CryptCATOpen

/*********************************************************************** *      CryptCATOpen  ([email
C++ CreateFilter函数代码示例
C++ CreateFileMapping函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。