如何确定Windows和Windows系统目录

来源:互联网 发布:ssl默认端口号 编辑:程序博客网 时间:2024/06/05 20:42
有两个SDK函数可以完成该功能。GetWindowsDirectory和GetSystemDirectory,
TCHAR szDir [MAX_PATH];
//Get the full path of the windows directory.
:: GetWindowsDirectory (szDir, MAX_PATH);
TRACE ("Windows directory %s/n", szDir);
//Get the full path of the windows system directory.
:: GetSystemDirectory (szDir, MAX_PATH);
:: GetSystemDirectory (szDir, MAX_PATH);
    调用SDK函数GetTemPath可以确定临时文件的目录,该函数首先为临时路径
检测TMP环境变量:如果没有指定TMP,检测TMP环境变量,然后返回到当前目录。
下例说明了如何创建一个临时文件。

     //get unique temporary file.
     CString strFile;
     TRY
     {
        //Create file and write data.Note that file is closed
        //in the destructor of the CFile object.
        //write data
     CATCH (CFileException, e)
     CATCH (CFileException, e)
     {
        //error opening file
     }
     END_CATCH
Void GetuniqueTempName (CString& strTempName)
{
     //Get the temporary files directory.
     TCHAR szTempPath  [MAX_PATH];
     DWORD dwResult=:: GetTempPath (MAX_PATH, szTempPath);
     //Create a unique temporary file.
     TCHAR szTempFile  [MAX_PATH];
     UINT nResult=GetTempFileName (szTempPath, _T ("~ex"),0,szTempfile);
     strTempName=szTempFile;
}
原创粉丝点击