相当于Windows Phone上的GetTempPath

时间:2015-08-19 15:30:23

标签: visual-studio winapi winrt-component

我正在为Windows Universal App编译第三方库 libkml 。我注意到除WINAPI_PARTITION_DESKTOP之外的任何内容都没有以下Win32 API。

以下内容来自 fileapi.h

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

WINBASEAPI
DWORD
WINAPI
GetTempPathW(
    _In_ DWORD nBufferLength,
    _Out_writes_to_opt_(nBufferLength, return + 1) LPWSTR lpBuffer
    );
... 
#endif

有没有人知道Windows Store App和Windows Phone App的此GetTempPath的等效功能?

2 个答案:

答案 0 :(得分:3)

以下是一个示例GetTemporaryDirectory()包装函数,取自以下MSDN博客文章“为Windows Store和Win32桌面应用程序编写共享代码”:

Dual-use Coding Techniques for Games, part 3

void GetTemporaryDirectory( wchar_t* dir, size_t maxsize )
{
    if ( !maxsize ) return;
    *dir = 0;
    #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
    DWORD nChars = GetTempPath( maxsize, dir );
    if ( nChars > 0 )
        dir[nChars-1] = '\0'; // Trim trialing '\'
    else
        *dir = 0;
    #else // Windows Store WinRT app
    auto folder = Windows::Storage::ApplicationData::Current->TemporaryFolder;
    wcscpy_s( dir, maxsize, folder->Path->Data() );
    #endif // WINAPI_FAMILY_PARTITION
} 

答案 1 :(得分:1)