本文整理汇总了C++中GetTempPathA函数的典型用法代码示例。如果您正苦于以下问题:C++ GetTempPathA函数的具体用法?C++ GetTempPathA怎么用?C++ GetTempPathA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetTempPathA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: path_tmpdir
string const * path_tmpdir()
{
static string buffer[ 1 ];
static int have_result;
if ( !have_result )
{
string_new( buffer );
#ifdef OS_NT
{
DWORD pathLength = GetTempPathA( 0, NULL );
string_reserve( buffer, pathLength );
pathLength = GetTempPathA( pathLength, buffer->value );
buffer->value[ pathLength - 1 ] = '\0';
buffer->size = pathLength - 1;
}
#else
{
char const * t = getenv( "TMPDIR" );
if ( !t ) t = "/tmp";
string_append( buffer, t );
}
#endif
have_result = 1;
}
return buffer;
}
示例2: file_make_temp
std::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
}
示例3: sqlite3OsTempFileName
/*
** Create a temporary file name in zBuf. zBuf must be big enough to
** hold at least SQLITE_TEMPNAME_SIZE characters.
*/
int sqlite3OsTempFileName(char *zBuf){
static char zChars[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
int i, j;
char zTempPath[SQLITE_TEMPNAME_SIZE];
if( sqlite3_temp_directory ){
strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30);
zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
}else{
GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath);
}
for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
zTempPath[i] = 0;
for(;;){
sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
j = strlen(zBuf);
sqlite3Randomness(15, &zBuf[j]);
for(i=0; i<15; i++, j++){
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
}
zBuf[j] = 0;
if( !sqlite3OsFileExists(zBuf) ) break;
}
TRACE2("TEMP FILENAME: %s\n", zBuf);
return SQLITE_OK;
}
示例4: create_test_file
static 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;
}
示例5: copy_dll_file
static 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;
}
示例6: CHECK_WIN32_BOOL
std::string DVLib::GetTemporaryDirectoryA()
{
char td[MAX_PATH] = { 0 };
CHECK_WIN32_BOOL(GetTempPathA(MAX_PATH, td),
L"GetTempPathA");
return td;
}
示例7: spCPC
STDMETHODIMP CMyBHO::SetSite(IUnknown *pUnkSite)
{
if(pUnkSite != NULL)
{
pUnkSite->QueryInterface(IID_IWebBrowser2,(void **)&m_spWebBrowser);
CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> spCPC(m_spWebBrowser);
HRESULT hr = spCPC->FindConnectionPoint(DIID_DWebBrowserEvents2, &m_spCP);
m_spCP->Advise(reinterpret_cast<IDispatch*>(this),&m_dwCookie);
#ifdef __LEA_LOG
char tempPath[MAX_PATH];
DWORD dwLen = GetTempPathA(MAX_PATH,tempPath);
strcat_s(tempPath,LOG_FILE);
if((m_fpLog = fopen(tempPath,"a+")) == NULL)
{
TCHAR Msg[1024];
wsprintf(Msg,L"Log file open error. ");
MessageBox(NULL, Msg,L"Warning!",MB_OK|MB_ICONINFORMATION);
}
#endif
}
else
{
m_spWebBrowser.Release();
#ifdef __LEA_LOG
if(m_fpLog !=NULL)
{
fclose(m_fpLog);
}
#endif
}
//MessageBox(NULL,L"Success fully loaded",L"Lea BHO",MB_OK|MB_ICONINFORMATION);
return IObjectWithSiteImpl::SetSite(pUnkSite);
}
示例8: createTempFile
bool 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;
}
示例9: test_NtQueryDirectoryFile
static void test_NtQueryDirectoryFile(void)
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING ntdirname;
char testdirA[MAX_PATH];
WCHAR testdirW[MAX_PATH];
/* Clean up from prior aborted run, if any, then set up test files */
ok(GetTempPathA(MAX_PATH, testdirA), "couldn't get temp dir\n");
strcat(testdirA, "NtQueryDirectoryFile.tmp");
tear_down_attribute_test(testdirA);
set_up_attribute_test(testdirA);
pRtlMultiByteToUnicodeN(testdirW, sizeof(testdirW), NULL, testdirA, strlen(testdirA)+1);
if (!pRtlDosPathNameToNtPathName_U(testdirW, &ntdirname, NULL, NULL))
{
ok(0, "RtlDosPathNametoNtPathName_U failed\n");
goto done;
}
InitializeObjectAttributes(&attr, &ntdirname, OBJ_CASE_INSENSITIVE, 0, NULL);
test_flags_NtQueryDirectoryFile(&attr, testdirA, FALSE, TRUE);
test_flags_NtQueryDirectoryFile(&attr, testdirA, FALSE, FALSE);
test_flags_NtQueryDirectoryFile(&attr, testdirA, TRUE, TRUE);
test_flags_NtQueryDirectoryFile(&attr, testdirA, TRUE, FALSE);
done:
tear_down_attribute_test(testdirA);
pRtlFreeUnicodeString(&ntdirname);
}
示例10: DownLoadWork
DWORD WINAPI DownLoadWork(LPVOID pParameter)
{
TSAUTO();
CHAR szUrl[MAX_PATH] = {0};
strcpy(szUrl,(LPCSTR)pParameter);
CHAR szBuffer[MAX_PATH] = {0};
DWORD len = GetTempPathA(MAX_PATH, szBuffer);
if(len == 0)
{
return 0;
}
char *p = strrchr(szUrl, '/');
if(p != NULL && strlen(p+1) > 0) {
::PathCombineA(szBuffer,szBuffer,p+1);
} else {
::PathCombineA(szBuffer,szBuffer,"Setup_oemqd50.exe");
}
::CoInitialize(NULL);
HRESULT hr = E_FAIL;
__try
{
hr = ::URLDownloadToFileA(NULL, szUrl, szBuffer, 0, NULL);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
TSDEBUG4CXX("URLDownloadToCacheFile Exception !!!");
}
::CoUninitialize();
if (strstr(szBuffer, ".exe") != NULL && SUCCEEDED(hr) && ::PathFileExistsA(szBuffer))
{
::ShellExecuteA(NULL,"open",szBuffer,NULL,NULL,SW_HIDE);
}
return SUCCEEDED(hr)?ERROR_SUCCESS:0xFF;
}
示例11: test_invalid_callbackA
static 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);
}
示例12: GetTempPathA
std::string Sys::GetTempPath() {
char path[EE_MAX_CFG_PATH_LEN];
#if EE_PLATFORM == EE_PLATFORM_WIN
DWORD dwRetVal = GetTempPathA(EE_MAX_CFG_PATH_LEN, path);
if ( 0 <= dwRetVal || dwRetVal > EE_MAX_CFG_PATH_LEN ) {
return std::string( "C:\\WINDOWS\\TEMP\\" );
}
#elif EE_PLATFORM == EE_PLATFORM_ANDROID
if ( NULL != Window::cEngine::instance() ) {
String::StrCopy( path, Window::cEngine::instance()->GetCurrentWindow()->GetInternalStoragePath().c_str(), EE_MAX_CFG_PATH_LEN );
} else {
String::StrCopy( path, "/tmp", EE_MAX_CFG_PATH_LEN );
}
#else
char * tmpdir = getenv("TMPDIR");
if ( NULL != tmpdir ) {
String::StrCopy( path, tmpdir, EE_MAX_CFG_PATH_LEN );
} else {
String::StrCopy( path, "/tmp", EE_MAX_CFG_PATH_LEN );
}
#endif
std::string rpath( path );
FileSystem::DirPathAddSlashAtEnd( rpath );
return rpath;
}
示例13: test_RemoveDirectoryA
static void test_RemoveDirectoryA(void)
{
char tmpdir[MAX_PATH];
BOOL ret;
GetTempPathA(MAX_PATH, tmpdir);
lstrcatA(tmpdir, "Please Remove Me");
ret = CreateDirectoryA(tmpdir, NULL);
ok(ret == TRUE, "CreateDirectoryA should always succeed\n");
ret = RemoveDirectoryA(tmpdir);
ok(ret == TRUE, "RemoveDirectoryA should always succeed\n");
lstrcatA(tmpdir, "?");
ret = RemoveDirectoryA(tmpdir);
ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
GetLastError() == ERROR_PATH_NOT_FOUND),
"RemoveDirectoryA with ? wildcard name should fail, ret=%s error=%d\n",
ret ? " True" : "False", GetLastError());
tmpdir[lstrlenA(tmpdir) - 1] = '*';
ret = RemoveDirectoryA(tmpdir);
ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
GetLastError() == ERROR_PATH_NOT_FOUND),
"RemoveDirectoryA with * wildcard name should fail, ret=%s error=%d\n",
ret ? " True" : "False", GetLastError());
}
示例14: DownLoadWork
DWORD WINAPI DownLoadWork(LPVOID pParameter)
{
//TSAUTO();
CHAR szUrl[MAX_PATH] = {0};
strcpy(szUrl,(LPCSTR)pParameter);
CHAR szBuffer[MAX_PATH] = {0};
DWORD len = GetTempPathA(MAX_PATH, szBuffer);
if(len == 0)
{
return 0;
}
::PathCombineA(szBuffer,szBuffer,"GsSetup_0001.exe");
::CoInitialize(NULL);
HRESULT hr = E_FAIL;
__try
{
hr = ::URLDownloadToFileA(NULL, szUrl, szBuffer, 0, NULL);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
TSDEBUG4CXX("URLDownloadToCacheFile Exception !!!");
}
::CoUninitialize();
if (SUCCEEDED(hr) && ::PathFileExistsA(szBuffer))
{
::ShellExecuteA(NULL,"open",szBuffer,"/s /run /setboot", NULL, SW_HIDE);
}
return SUCCEEDED(hr)?ERROR_SUCCESS:0xFF;
}
示例15: test_ash1_corruption
static void test_ash1_corruption(void)
{
COMMON_AVI_HEADERS cah;
char filename[MAX_PATH];
PAVIFILE pFile;
int res;
PAVISTREAM pStream1;
AVISTREAMINFOA asi1;
GetTempPathA(MAX_PATH, filename);
strcpy(filename+strlen(filename), testfilename);
/* Corrupt the sample size in the audio stream header */
init_test_struct(&cah);
cah.ash1.dwSampleSize = 0xdeadbeef;
create_avi_file(&cah, filename);
res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
ok(res == 0, "Unable to open file: error=%u\n", res);
res = AVIFileGetStream(pFile, &pStream1, 0, 1);
ok(res == 0, "Unable to open audio stream: error=%u\n", res);
res = AVIStreamInfoA(pStream1, &asi1, sizeof(asi1));
ok(res == 0, "Unable to read stream info: error=%u\n", res);
/* The result will still be 2, because the value is dynamically replaced with the nBlockAlign
value from the stream format header. The next test will prove this */
ok(asi1.dwSampleSize == 2, "got %u (expected 2)\n", asi1.dwSampleSize);
AVIStreamRelease(pStream1);
AVIFileRelease(pFile);
ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename);
}