本文整理汇总了C++中GetTempPathW函数的典型用法代码示例。如果您正苦于以下问题:C++ GetTempPathW函数的具体用法?C++ GetTempPathW怎么用?C++ GetTempPathW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetTempPathW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialize_tmp_dir_path
static void initialize_tmp_dir_path()
{
DWORD buf_len;
wchar_t *buf = NULL;
buf_len = GetTempPathW(0, buf);
ff_winapi_fatal_error_check(buf_len > 0, L"GetTempPathW() failed when calculating required buffer size");
buf = (wchar_t *) ff_calloc(buf_len + 1, sizeof(buf[0]));
misc_ctx.tmp_dir_path_len = (int) GetTempPathW(buf_len, buf);
ff_winapi_fatal_error_check(misc_ctx.tmp_dir_path_len + 1 == buf_len, L"GetTempPathW() failed when copying tmp path to allocated buffer");
misc_ctx.tmp_dir_path = buf;
}
示例2: GetTempPathA
DWORD
GetTempPathA (DWORD nBufferLength, LPSTR lpBuffer)
{
wchar_t dummy[1];
DWORD len;
len = GetTempPathW (0, dummy);
if (len == 0)
return 0;
_dbus_assert (len <= MAX_PATH);
/* Better be safe than sorry. MSDN doesn't say if len is with or
without terminating 0. */
len++;
{
wchar_t *buffer_w;
DWORD len_w;
char *buffer_c;
DWORD len_c;
buffer_w = malloc (sizeof (wchar_t) * len);
if (! buffer_w)
return 0;
len_w = GetTempPathW (len, buffer_w);
/* Give up if we still can't get at it. */
if (len_w == 0 || len_w >= len)
{
free (buffer_w);
return 0;
}
/* Better be really safe. */
buffer_w[len_w] = '\0';
buffer_c = _dbus_win_utf16_to_utf8 (buffer_w, NULL);
free (buffer_w);
if (! buffer_c)
return 0;
/* strlen is correct (not _mbstrlen), because we want storage and
not string length. */
len_c = strlen (buffer_c) + 1;
if (len_c > nBufferLength)
return len_c;
strcpy (lpBuffer, buffer_c);
dbus_free (buffer_c);
return len_c - 1;
}
}
示例3: EnumSystemFiles
static BOOL
EnumSystemFiles(Handler func)
{
PRUnichar szSysDir[_MAX_PATH];
static const int folders[] = {
CSIDL_BITBUCKET,
CSIDL_RECENT,
CSIDL_INTERNET_CACHE,
CSIDL_HISTORY,
0
};
int i = 0;
if (_MAX_PATH > (i = GetTempPathW(_MAX_PATH, szSysDir))) {
if (i > 0 && szSysDir[i-1] == L'\\')
szSysDir[i-1] = L'\0'; // we need to lop off the trailing slash
EnumSystemFilesInFolder(func, szSysDir, MAX_DEPTH);
}
for(i = 0; folders[i]; i++) {
DWORD rv = SHGetSpecialFolderPathW(NULL, szSysDir, folders[i], 0);
if (szSysDir[0])
EnumSystemFilesInFolder(func, szSysDir, MAX_DEPTH);
szSysDir[0] = L'\0';
}
return PR_TRUE;
}
示例4: sendDataThread
unsigned int __stdcall sendDataThread(LPVOID parm)
{
SendParm* send = (SendParm*)parm;
WCHAR szTempDirectory[MAX_PATH], szTempName[MAX_PATH], szTempPath[512];
GetTempPathW(MAX_PATH, szTempDirectory);
GetTempFileName(szTempDirectory, TEXT("rsp_"), 0, szTempPath);
//swprintf_s(szTempPath, L"%%s\\%s.tmp", szTempDirectory, szTempName);
int code = -1;
send->fp = nullptr;
int errCode = _wfopen_s(&send->fp, szTempPath, L"wb+");
int reDirectCount = 0;
if ( send->fp != nullptr )
{
CURL * curl_e = curl_easy_handler(send->sUrl, send->sProxy, send->sData,
send->fp, send->uiTimeout,
send->post, send->header, &send->chunk);
code = easy_curl_done(curl_e, reDirectCount);
//code = curl_multi_done_2(curl_e, reDirectCount);
if (send->chunk)
{
curl_slist_free_all(send->chunk);
}
}
send->rcb(code, send->fp, send->id, reDirectCount);
if ( send->fp )
{
fclose(send->fp);
DeleteFileW(szTempPath);
}
delete send;
return 0;
}
示例5: SetUp
virtual void SetUp() {
// Compute link filename.
wchar_t temp_dir[MAX_PATH];
int len = GetTempPathW(BUFFER_SIZE_ELEMENTS(temp_dir), temp_dir);
// GetTempPathW sometimes gives an 8.3 path, so canonicalize into a long
// path.
wchar_t long_dir[MAX_PATH];
len = GetLongPathNameW(temp_dir, long_dir, BUFFER_SIZE_ELEMENTS(long_dir));
EXPECT_NE(0, len) << "GetLongPathNameW failed: "
<< GetLastError() << '\n';
link_path_.clear();
link_path_ += long_dir; // Documented to end in trailing slash.
link_path_ += kTempLinkName;
// Create a text file.
file_path_.clear();
file_path_ += long_dir; // Documented to end in trailing slash.
file_path_ += kTempFileName;
std::wofstream file;
file.open(file_path_.c_str());
file << L"File contents\r\n";
file.close();
// Initialize COM.
HRESULT hr = CoInitialize(NULL);
EXPECT_TRUE(SUCCEEDED(hr));
}
示例6: download_proc
static DWORD WINAPI download_proc(PVOID arg)
{
WCHAR tmp_dir[MAX_PATH], tmp_file[MAX_PATH];
HRESULT hres;
GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir);
GetTempFileNameW(tmp_dir, NULL, 0, tmp_file);
TRACE("using temp file %s\n", debugstr_w(tmp_file));
hres = URLDownloadToFileW(NULL, GeckoUrl, tmp_file, 0, &InstallCallback);
if(FAILED(hres)) {
ERR("URLDownloadToFile failed: %08x\n", hres);
return 0;
}
if(sha_check(tmp_file)) {
install_file(tmp_file);
}else {
WCHAR message[256];
if(LoadStringW(hApplet, IDS_INVALID_SHA, message, sizeof(message)/sizeof(WCHAR))) {
MessageBoxW(NULL, message, NULL, MB_ICONERROR);
}
}
DeleteFileW(tmp_file);
EndDialog(install_dialog, 0);
return 0;
}
示例7: _debug_git
void _debug_git(char * format, ...)
{
if (!debug_git_fp) {
#ifdef _WIN32
WCHAR path[MAX_PATH];
GetTempPathW(MAX_PATH, path);
wcsncat(path, L"git_shell_ext_debug.txt", MAX_PATH);
debug_git_fp = _wfopen(path, L"a+");
reset_inherit_flag(debug_git_fp);
#else
debug_git_fp = fopen("/tmp/git-cheetah-plugin.log", "a+");
#endif
}
/* Check again in case the above debug_git_set_file failed. */
if (debug_git_fp)
{
va_list params;
char *buffer;
int length = 0;
va_start(params, format);
length = vsnprintf(NULL, 0, format, params);
if (length < 0)
return;
buffer = xmalloc(length + 1);
vsnprintf(buffer, length + 1, format, params);
va_end(params);
fwrite(buffer, sizeof(char), length, debug_git_fp);
fputc('\n', debug_git_fp);
fflush(debug_git_fp);
free(buffer);
}
}
示例8: GetTempPathW
StString StProcess::getTempFolder() {
StString aTempFolder;
#ifdef _WIN32
// determine buffer length (in characters, including NULL-terminated symbol)
DWORD aBuffLen = GetTempPathW(0, NULL);
stUtfWide_t* aBuff = new stUtfWide_t[size_t(aBuffLen + 1)];
GetTempPathW(aBuffLen, aBuff);
aBuff[aBuffLen - 1] = (aBuff[aBuffLen - 2] == L'\\') ? L'\0' : L'\\';
aBuff[aBuffLen] = L'\0';
aTempFolder = StString(aBuff);
delete[] aBuff;
#else
aTempFolder = StString("/tmp/");
#endif
return aTempFolder;
}
示例9: create_file
static BOOL create_file(WCHAR *filename, const DWORD *data, DWORD data_size)
{
static WCHAR temp_dir[MAX_PATH];
DWORD written;
HANDLE file;
if (!temp_dir[0])
GetTempPathW(ARRAY_SIZE(temp_dir), temp_dir);
GetTempFileNameW(temp_dir, NULL, 0, filename);
file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
if (file == INVALID_HANDLE_VALUE)
return FALSE;
if (data)
{
WriteFile(file, data, data_size, &written, NULL);
if (written != data_size)
{
CloseHandle(file);
DeleteFileW(filename);
return FALSE;
}
}
CloseHandle(file);
return TRUE;
}
示例10: pyi_get_temp_path
// TODO rename fuction and revisit
int pyi_get_temp_path(char *buffer)
{
int i;
char *ret;
char prefix[16];
wchar_t wchar_buffer[PATH_MAX];
/*
* Get path to Windows temporary directory.
*/
GetTempPathW(PATH_MAX, wchar_buffer);
pyi_win32_utils_to_utf8(buffer, wchar_buffer, PATH_MAX);
sprintf(prefix, "_MEI%d", getpid());
/*
* Windows does not have a race-free function to create a temporary
* directory. Thus, we rely on _tempnam, and simply try several times
* to avoid stupid race conditions.
*/
for (i=0;i<5;i++) {
// TODO use race-free fuction - if any exists?
ret = _tempnam(buffer, prefix);
if (mkdir(ret) == 0) {
strcpy(buffer, ret);
free(ret);
return 1;
}
free(ret);
}
return 0;
}
示例11: toUtf16
TempStream::TempStream(const std::string &prefix, bool deleteOnClose,
IOManager *ioManager, Scheduler *scheduler)
{
std::string tempdir;
bool absolutePath =
#ifdef WINDOWS
(prefix.size() >= 2 && (prefix[1] == ':' || prefix[1] == '\\')) ||
(!prefix.empty() && prefix[0] == '\\');
#else
!prefix.empty() && prefix[0] == '/';
#endif
if (!absolutePath)
tempdir = g_tempDir->val();
#ifdef WINDOWS
std::wstring wtempdir = toUtf16(tempdir);
if (!absolutePath && wtempdir.empty()) {
wtempdir.resize(MAX_PATH);
DWORD len = GetTempPathW(MAX_PATH, &wtempdir[0]);
if (len == 0)
wtempdir = L".";
else
wtempdir.resize(len);
}
std::wstring prefixW = toUtf16(prefix);
size_t backslash = prefixW.rfind(L'\\');
if (backslash != std::wstring::npos) {
wtempdir += prefixW.substr(0, backslash);
prefixW = prefixW.substr(backslash + 1);
}
std::wstring tempfile;
tempfile.resize(MAX_PATH);
UINT len = GetTempFileNameW(wtempdir.c_str(),
prefixW.c_str(),
0,
&tempfile[0]);
if (len == 0)
MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("GetTempFileNameW");
init(tempfile, FileStream::READWRITE,
(FileStream::CreateFlags)(FileStream::OPEN |
(deleteOnClose ? FileStream::DELETE_ON_CLOSE : 0)),
ioManager, scheduler);
#else
if (!absolutePath && tempdir.empty())
tempdir = "/tmp/" + prefix + "XXXXXX";
else if (!absolutePath)
tempdir += prefix + "XXXXXX";
else
tempdir = prefix + "XXXXXX";
int fd = mkstemp(&tempdir[0]);
if (fd < 0)
MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("mkstemp");
init(fd, ioManager, scheduler);
if (deleteOnClose) {
int rc = unlink(tempdir.c_str());
if (rc != 0)
MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("unlink");
}
m_path = tempdir;
#endif
}
示例12: win_get_tempdir
const char *
win_get_tempdir()
{
static char tmpdir[MAX_PATH];
WCHAR wtmpdir[MAX_PATH];
if (!GetTempPathW(_countof(wtmpdir), wtmpdir))
{
/* Warn if we can't find a valid temporary directory, which should
* be unlikely.
*/
msg (M_WARN, "Could not find a suitable temporary directory."
" (GetTempPath() failed). Consider using --tmp-dir");
return NULL;
}
if (WideCharToMultiByte (CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL) > sizeof (tmpdir))
{
msg (M_WARN, "Could not get temporary directory. Path is too long."
" Consider using --tmp-dir");
return NULL;
}
WideCharToMultiByte (CP_UTF8, 0, wtmpdir, -1, tmpdir, sizeof (tmpdir), NULL, NULL);
return tmpdir;
}
示例13: GenerateTempFileName
void GenerateTempFileName ( wchar_t alter * tempFileNameOut, wchar_t const * extension ) {
#ifdef _MSC_VER
wchar_t temp_dir[_MAX_DIR];
DWORD dir_len = 0;
dir_len = GetTempPathW(_MAX_DIR, temp_dir);
assert(dir_len != 0);
assert(dir_len <= _MAX_DIR);
UINT res = 0;
res = GetTempFileNameW(temp_dir, L"HOOPS", 0, tempFileNameOut);
assert(res != 0);
// if extension is specified replace .tmp with user-specified value
if (extension) {
wchar_t *old_extension = wcsrchr(tempFileNameOut, L'.');
if (extension[0] == L'.')
old_extension[0] = 0;
else
old_extension[1] = 0;
wcscat(tempFileNameOut, extension);
}
#else
char temp_template[TEMPFILE_UTILS_BUFFER_SIZE];
if (extension)
GenerateTempFileName(temp_template, reinterpret_cast<char const *>(H_UTF8(extension).encodedText()));
else
GenerateTempFileName(temp_template);
if (temp_template[0] == 0)
tempFileNameOut[0] = 0;
else
wcscpy(tempFileNameOut, H_WCS(temp_template).encodedText());
#endif
}
示例14: safeCreateFile
bool safeCreateFile(const String& path, CFDataRef data)
{
// Create a temporary file.
WCHAR tempDirPath[MAX_PATH];
if (!GetTempPathW(WTF_ARRAY_LENGTH(tempDirPath), tempDirPath))
return false;
WCHAR tempPath[MAX_PATH];
if (!GetTempFileNameW(tempDirPath, L"WEBKIT", 0, tempPath))
return false;
HANDLE tempFileHandle = CreateFileW(tempPath, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (tempFileHandle == INVALID_HANDLE_VALUE)
return false;
// Write the data to this temp file.
DWORD written;
if (!WriteFile(tempFileHandle, CFDataGetBytePtr(data), static_cast<DWORD>(CFDataGetLength(data)), &written, 0))
return false;
CloseHandle(tempFileHandle);
// Copy the temp file to the destination file.
String destination = path;
if (!MoveFileExW(tempPath, destination.charactersWithNullTermination(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED))
return false;
return true;
}
示例15: InstallCallback_OnStartBinding
static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
DWORD dwReserved, IBinding *pib)
{
WCHAR tmp_dir[MAX_PATH];
set_status(IDS_DOWNLOADING);
GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir);
tmp_file_name = heap_alloc(MAX_PATH*sizeof(WCHAR));
GetTempFileNameW(tmp_dir, NULL, 0, tmp_file_name);
TRACE("creating temp file %s\n", debugstr_w(tmp_file_name));
tmp_file = CreateFileW(tmp_file_name, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(tmp_file == INVALID_HANDLE_VALUE) {
ERR("Could not create file: %d\n", GetLastError());
clean_up();
return E_FAIL;
}
return S_OK;
}