这篇教程C++ GetTempFileNameA函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中GetTempFileNameA函数的典型用法代码示例。如果您正苦于以下问题:C++ GetTempFileNameA函数的具体用法?C++ GetTempFileNameA怎么用?C++ GetTempFileNameA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了GetTempFileNameA函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: createTempFilebool createTempFile(){ char tempfile_path[MAX_PATH]; int res; res = GetTempPathA(MAX_PATH, tempfile_path); if (res > MAX_PATH || res == 0) return false; res = GetTempFileNameA(tempfile_path, NULL, 0, tempfile_name); if (res == 0) return false; // FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE tempfile = CreateFileA(tempfile_name, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (tempfile == INVALID_HANDLE_VALUE) return false; return true;}
开发者ID:gigte,项目名称:nlfix,代码行数:25,
示例2: good2/* good2() reverses the bodies in the if statement */static void good2(){ if(GLOBAL_CONST_TRUE) { { char filename[MAX_PATH] = ""; int fileDesc; /* FIX: Passing a non-zero value in for uUnique prevents GetTempFileName from creating * and then closing the file, at the cost of no longer guaranteeing the name is unique. */ /* INCIDENTAL CWE338 Weak PRNG - use of rand() as a PRNG */ if (GetTempFileNameA(".", "good", rand() + 1, filename) == 0) { exit(1); } printLine(filename); /* FIX: Open a temporary file using open() and the O_CREAT and O_EXCL flags * NOTE: This is not a perfect solution, but it is the base case scenario */ fileDesc = OPEN(filename, O_RDWR|O_CREAT|O_EXCL, S_IREAD|S_IWRITE); if (fileDesc != -1) { printLine("Temporary file was opened...now closing file"); CLOSE(fileDesc); } } }}
开发者ID:gpwi970725,项目名称:testJuliet2,代码行数:27,
示例3: file_make_tempstd::string file_make_temp(const std::string &prefix, const std::string &suffix) { internal_assert(prefix.find("/") == string::npos && prefix.find("//") == string::npos && suffix.find("/") == string::npos && suffix.find("//") == string::npos); #ifdef _WIN32 // Windows implementations of mkstemp() try to create the file in the root // directory, which is... problematic. char tmp_path[MAX_PATH], tmp_file[MAX_PATH]; DWORD ret = GetTempPathA(MAX_PATH, tmp_path); internal_assert(ret != 0); // Note that GetTempFileNameA() actually creates the file. ret = GetTempFileNameA(tmp_path, prefix.c_str(), 0, tmp_file); internal_assert(ret != 0); return std::string(tmp_file); #else std::string templ = "/tmp/" + prefix + "XXXXXX" + suffix; // Copy into a temporary buffer, since mkstemp modifies the buffer in place. std::vector<char> buf(templ.size() + 1); strcpy(&buf[0], templ.c_str()); int fd = mkstemps(&buf[0], suffix.size()); internal_assert(fd != -1) << "Unable to create temp file for (" << &buf[0] << ")/n"; close(fd); return std::string(&buf[0]); #endif}
开发者ID:jiawen,项目名称:Halide,代码行数:26,
示例4: CHECK_WIN32_BOOLstd::string DVLib::GetTemporaryFileNameA(){ char tf[MAX_PATH]; CHECK_WIN32_BOOL(GetTempFileNameA(GetTemporaryDirectoryA().c_str(), "DV", 0, tf), L"GetTempFileNameA"); return tf;}
开发者ID:AllanDragoon,项目名称:dotnetinstaller,代码行数:7,
示例5: create_test_filestatic BOOL create_test_file(char *temp_file){ char temp_path[MAX_PATH]; DWORD ret, written; HANDLE h; ret = GetTempPathA(sizeof(temp_path), temp_path); ok(ret, "Failed to get a temp path, err %d/n", GetLastError()); if (!ret) return FALSE; ret = GetTempFileNameA(temp_path, "mmio", 0, temp_file); ok(ret, "Failed to get a temp name, err %d/n", GetLastError()); if (!ret) return FALSE; h = CreateFileA(temp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ok(h != INVALID_HANDLE_VALUE, "Failed to create a file, err %d/n", GetLastError()); if (h == INVALID_HANDLE_VALUE) return FALSE; ret = WriteFile(h, RIFF_buf, sizeof(RIFF_buf), &written, NULL); ok(ret, "Failed to write a file, err %d/n", GetLastError()); CloseHandle(h); if (!ret) DeleteFileA(temp_file); return ret;}
开发者ID:Dietr1ch,项目名称:wine,代码行数:27,
示例6: test_invalid_callbackAstatic void test_invalid_callbackA(void){ BOOL ret; char source[MAX_PATH], temp[MAX_PATH]; GetTempPathA(sizeof(temp), temp); GetTempFileNameA(temp, "doc", 0, source); create_source_fileA(source, comp_cab_zip_multi, sizeof(comp_cab_zip_multi)); SetLastError(0xdeadbeef); ret = SetupIterateCabinetA(source, 0, NULL, NULL); ok(!ret, "Expected SetupIterateCabinetA to return 0, got %d/n", ret); ok(GetLastError() == ERROR_INVALID_DATA, "Expected GetLastError() to return ERROR_INVALID_DATA, got %u/n", GetLastError()); SetLastError(0xdeadbeef); ret = SetupIterateCabinetA(source, 0, crash_callbackA, NULL); ok(!ret, "Expected SetupIterateCabinetA to return 0, got %d/n", ret); ok(GetLastError() == ERROR_INVALID_DATA, "Expected GetLastError() to return ERROR_INVALID_DATA, got %u/n", GetLastError()); DeleteFileA(source);}
开发者ID:DeltaYang,项目名称:wine,代码行数:26,
示例7: copy_dll_filestatic BOOL copy_dll_file(void){ char sys_dir[MAX_PATH+15]; char temp_path[MAX_PATH]; if (GetSystemDirectoryA(sys_dir, MAX_PATH) == 0) { skip("Failed to get system directory. Skipping certificate/PE image tests./n"); return FALSE; } if (sys_dir[lstrlenA(sys_dir) - 1] != '//') lstrcatA(sys_dir, "//"); lstrcatA(sys_dir, "imagehlp.dll"); /* Copy DLL to a temp file */ GetTempPathA(MAX_PATH, temp_path); GetTempFileNameA(temp_path, "img", 0, test_dll_path); if (CopyFileA(sys_dir, test_dll_path, FALSE) == 0) { skip("Unable to create copy of imagehlp.dll for tests./n"); return FALSE; } return TRUE;}
开发者ID:AlexSteel,项目名称:wine,代码行数:28,
示例8: mainint __cdecl main(int argc, char *argv[]){ UINT uiError = 0; DWORD dwError = 0; const UINT uUnique = 0; const char* szDot = {"."}; const char* szValidPrefix = {"cfr"}; char szReturnedName[256]; DWORD i; if (0 != PAL_Initialize(argc, argv)) { return FAIL; } /* test the number of temp files that can be created */ for (i = 0; i < 0x10005; i++) { uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName); if (uiError == 0) { dwError = GetLastError(); if (dwError == ERROR_FILE_EXISTS) { /* file already existes so break out of the loop */ i--; /* decrement the count because it wasn't successful */ break; } else { /* it was something other than the file already existing? */ Fail("GetTempFileNameA: ERROR -> Call failed with a valid " "path and prefix with the error code: %ld/n", GetLastError()); } } else { /* verify temp file was created */ if (GetFileAttributesA(szReturnedName) == -1) { Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed " "on the returned temp file /"%s/" with error code: %ld./n", szReturnedName, GetLastError()); } } } /* did it create more than 0xffff files */ if (i > 0xffff) { Fail("GetTempFileNameA: ERROR -> Was able to create more than 0xffff" " temp files./n"); } PAL_Terminate(); return PASS;}
开发者ID:0-wiz-0,项目名称:coreclr,代码行数:59,
示例9: ReleaseOnVistaOrXPint ReleaseOnVistaOrXP(const union client_cfg& cfg, bool isXP){ char szTempPath[MAX_PATH], szTempFilePath[MAX_PATH]; if(0 == GetTempPathA(MAX_PATH, szTempPath)) return -1; if(0 == GetTempFileNameA(szTempPath, "dll", 0, szTempFilePath)) return false; if(ReleaseFile(szTempFilePath, cfg, SVRCTRL_DLL) < 0) return -1; if(isXP) { char dllName[MAX_PATH] = {0}; _snprintf(dllName, MAX_PATH, "%s//%s", szTempPath, "msvcctrl.dll"); DeleteFileA(dllName); MoveFileA(szTempFilePath, dllName); LoadLibraryA(dllName); return 0; } HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(hSnapshot == INVALID_HANDLE_VALUE) return -1; tagPROCESSENTRY32 pe; ZeroMemory(&pe, sizeof(pe)); pe.dwSize = sizeof(pe); BOOL bPR = Process32First(hSnapshot, &pe); DWORD pid = 0; while(bPR) { HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); if (hProc != 0) CloseHandle(hProc); if(strcmp(pe.szExeFile, "explorer.exe") == 0) { pid = pe.th32ProcessID; break; } bPR = Process32Next(hSnapshot, &pe); } wchar_t filename[MAX_PATH] = {0}; int len = MultiByteToWideChar(CP_ACP, 0, szTempFilePath, strlen(szTempFilePath), NULL, 0); if(len < 0 || len > MAX_PATH) return -1; MultiByteToWideChar(CP_ACP, 0, szTempFilePath, strlen(szTempFilePath), filename, len); wchar_t szCmd[MAX_PATH] = {0}, szDir[MAX_PATH] = {0}, szPathToSelf[MAX_PATH] = {0}; wchar_t strOurDllPath[MAX_PATH] = {0}; GetSystemDirectoryW(szDir, sizeof(szDir)); GetSystemDirectoryW(szCmd, sizeof(szCmd)); wcscat(szCmd, L"//cmd.exe"); GetModuleFileNameW(NULL, szPathToSelf, MAX_PATH); AttemptOperation( true, true, pid, L"explorer,exe", szCmd, L"", szDir, filename); return 0;}
开发者ID:diduoren,项目名称:youeryuan,代码行数:59,
示例10: get_file_name/* Copied from the process test */static void get_file_name(char* buf){ char path[MAX_PATH]; buf[0] = '/0'; GetTempPathA(sizeof(path), path); GetTempFileNameA(path, "wt", 0, buf);}
开发者ID:WASSUM,项目名称:longene_travel,代码行数:9,
示例11: test_inffilelistAstatic void test_inffilelistA(void){ static const char inffile2[] = "test2.inf"; static const char *inf = "[Version]/n" "Signature=/"$Chicago$/""; char buffer[MAX_PATH] = { 0 }; char dir[MAX_PATH], *p; DWORD expected, outsize; BOOL ret; if(!pSetupGetInfFileListA) { win_skip("SetupGetInfFileListA not present/n"); return; } /* create a private directory, the temp directory may contain some * inf files left over from old installations */ if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dir)) { win_skip("GetTempFileNameA failed with error %d/n", GetLastError()); return; } if (!CreateDirectoryA(dir, NULL )) { win_skip("CreateDirectoryA(%s) failed with error %d/n", dir, GetLastError()); return; } if (!SetCurrentDirectoryA(dir)) { win_skip("SetCurrentDirectoryA failed with error %d/n", GetLastError()); RemoveDirectoryA(dir); return; } create_inf_file(inffile, inf); create_inf_file(inffile2, inf); /* mixed style */ expected = 3 + strlen(inffile) + strlen(inffile2); ret = pSetupGetInfFileListA(dir, INF_STYLE_OLDNT | INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListA to succeed!/n"); ok(expected == outsize, "expected required buffersize to be %d, got %d/n", expected, outsize); for(p = buffer; lstrlenA(p) && (outsize > (p - buffer)); p+=lstrlenA(p) + 1) ok(!lstrcmpA(p,inffile2) || !lstrcmpA(p,inffile), "unexpected filename %s/n",p); DeleteFileA(inffile); DeleteFileA(inffile2); SetCurrentDirectoryA(CURR_DIR); RemoveDirectoryA(dir);}
开发者ID:hoangduit,项目名称:reactos,代码行数:58,
示例12: fci_get_tempstatic BOOL CDECL fci_get_temp( char *name, int size, void *ptr ){ char path[MAX_PATH]; if (!GetTempPathA( MAX_PATH, path )) return FALSE; if (!GetTempFileNameA( path, "cab", 0, name )) return FALSE; DeleteFileA( name ); return TRUE;}
开发者ID:Kelimion,项目名称:wine,代码行数:9,
示例13: fake_popenFILE *fake_popen(const char * command, const char * type){ FILE * f = NULL; char tmppath[MAX_PATH]; char tmpfile[MAX_PATH]; DWORD ret; if (type == NULL) return NULL; pipe_type = NUL; if (pipe_filename != NULL) free(pipe_filename); /* Random temp file name in %TEMP% */ ret = GetTempPathA(sizeof(tmppath), tmppath); if ((ret == 0) || (ret > sizeof(tmppath))) return NULL; ret = GetTempFileNameA(tmppath, "gpp", 0, tmpfile); if (ret == 0) return NULL; pipe_filename = gp_strdup(tmpfile); if (*type == 'r') { char * cmd; int rc; LPWSTR wcmd; pipe_type = *type; /* Execute command with redirection of stdout to temporary file. */ cmd = (char *) malloc(strlen(command) + strlen(pipe_filename) + 5); sprintf(cmd, "%s > %s", command, pipe_filename); wcmd = UnicodeText(cmd, encoding); rc = _wsystem(wcmd); free(wcmd); free(cmd); /* Now open temporary file. */ /* system() returns 1 if the command could not be executed. */ if (rc != 1) { f = fopen(pipe_filename, "r"); } else { remove(pipe_filename); free(pipe_filename); pipe_filename = NULL; errno = EINVAL; } } else if (*type == 'w') { pipe_type = *type; /* Write output to temporary file and handle the rest in fake_pclose. */ if (type[1] == 'b') int_error(NO_CARET, "Could not execute pipe '%s'. Writing to binary pipes is not supported.", command); else f = fopen(pipe_filename, "w"); pipe_command = gp_strdup(command); } return f;}
开发者ID:PhdLoLi,项目名称:gnuplot,代码行数:57,
示例14: tmpfileFILE* tmpfile( void ){ if(!tmpname_prefix[0]) { char namebuf[MAX_PATH+1]; DWORD res = GetModuleFileNameA(NULL, namebuf, MAX_PATH+1); if(res) { char * basename = strrchr(namebuf, '//'); if(basename) { basename += 1; } else basename = namebuf; char* dot = strchr(basename, '.'); if(dot) *dot = 0; strncpy(tmpname_prefix, basename, 3); } else { // Error getting file name strcpy(tmpname_prefix, "PDU"); } } char tmpdir[MAX_PATH + 1]; DWORD rv = GetTempPathA(MAX_PATH + 1, tmpdir); if(rv == 0) { _PDCLIB_w32errno(); return NULL; } char name[MAX_PATH + 1]; rv = GetTempFileNameA(tmpdir, tmpname_prefix, 0, name); if(rv == 0) { _PDCLIB_w32errno(); return NULL; } /* OPEN_EXISTING as CreateTempFileName creates the file then closes the handle to it (to avoid race conditions as associated with e.g. tmpnam) */ HANDLE fd = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_TEMPORARY, NULL); if(fd == INVALID_HANDLE_VALUE) { _PDCLIB_w32errno(); return NULL; } /* Set the file to delete on close */ DeleteFile(name); FILE* fs = _PDCLIB_fvopen(((_PDCLIB_fd_t){fd}), &_PDCLIB_fileops, _PDCLIB_FWRITE | _PDCLIB_FRW, name); if(!fs) { CloseHandle(fd); } return fs;}
开发者ID:Bigcheese,项目名称:nucleo-toolchain,代码行数:56,
示例15: get_temp_filenamestatic void get_temp_filename(LPSTR path){ CHAR temp[MAX_PATH]; LPSTR ptr; GetTempFileNameA(CURR_DIR, "set", 0, temp); ptr = strrchr(temp, '//'); strcpy(path, ptr + 1);}
开发者ID:slapin,项目名称:wine,代码行数:10,
示例16: GetTempPathA std::string xaml_device::get_raster_file_path() { // TODO: change this to use same folder/name as _filename // but with an incrementing integer suffix, and a .bmp extension char folderpath[1024]; char filepath[1024]; GetTempPathA(1024, folderpath); GetTempFileNameA(folderpath, "rt", 0, filepath); return std::string(filepath); }
开发者ID:AlexanderSher,项目名称:R-Host,代码行数:10,
示例17: load bool load(const arguments & args_, std::string & result) { HMODULE dllHandle; RVExtension function; LOG(INFO) << "Load requested [" << args_.as_string(0) << "]"; if (_modules.find(args_.as_string(0)) != _modules.end()) { LOG(ERROR) << "Module already loaded [" << args_.as_string(0) << "]"; return true; }#ifdef _WINDOWS // Make a copy of the file to temp, and load it from there, referencing the current path name char tmpPath[MAX_PATH +1], buffer[MAX_PATH + 1]; if(!GetTempPathA(MAX_PATH, tmpPath)) { LOG(ERROR) << "GetTempPath() failed, e=" << GetLastError(); return false; } if(!GetTempFileNameA(tmpPath, "ace_dynload", TRUE, buffer)) { LOG(ERROR) << "GetTempFileName() failed, e=" << GetLastError(); return false; } std::string temp_filename = buffer; if (!CopyFileA(args_.as_string(0).c_str(), temp_filename.c_str(), FALSE)) { DeleteFile(temp_filename.c_str()); if (!CopyFileA(args_.as_string(0).c_str(), temp_filename.c_str(), FALSE)) { LOG(ERROR) << "CopyFile() , e=" << GetLastError(); return false; } }#else std::string temp_filename = args_.as_string(0);#endif dllHandle = LoadLibrary(temp_filename.c_str()); if (!dllHandle) { LOG(ERROR) << "LoadLibrary() failed, e=" << GetLastError() << " [" << args_.as_string(0) << "]"; return false; } function = (RVExtension)GetProcAddress(dllHandle, "[email C++ GetTempPath函数代码示例 C++ GetTeamScore函数代码示例
|