<i id='Pgirq'><tr id='Pgirq'><dt id='Pgirq'><q id='Pgirq'><span id='Pgirq'><b id='Pgirq'><form id='Pgirq'><ins id='Pgirq'></ins><ul id='Pgirq'></ul><sub id='Pgirq'></sub></form><legend id='Pgirq'></legend><bdo id='Pgirq'><pre id='Pgirq'><center id='Pgirq'></center></pre></bdo></b><th id='Pgirq'></th></span></q></dt></tr></i><div id='Pgirq'><tfoot id='Pgirq'></tfoot><dl id='Pgirq'><fieldset id='Pgirq'></fieldset></dl></div>
<tfoot id='Pgirq'></tfoot>

      • <bdo id='Pgirq'></bdo><ul id='Pgirq'></ul>
    1. <legend id='Pgirq'><style id='Pgirq'><dir id='Pgirq'><q id='Pgirq'></q></dir></style></legend>

      1. <small id='Pgirq'></small><noframes id='Pgirq'>

      2. 如何在代码中正确使用 %USERPROFILE%?

        How to properly use %USERPROFILE% inside code?(如何在代码中正确使用 %USERPROFILE%?)
          <tbody id='zD87j'></tbody>
      3. <legend id='zD87j'><style id='zD87j'><dir id='zD87j'><q id='zD87j'></q></dir></style></legend>

          <i id='zD87j'><tr id='zD87j'><dt id='zD87j'><q id='zD87j'><span id='zD87j'><b id='zD87j'><form id='zD87j'><ins id='zD87j'></ins><ul id='zD87j'></ul><sub id='zD87j'></sub></form><legend id='zD87j'></legend><bdo id='zD87j'><pre id='zD87j'><center id='zD87j'></center></pre></bdo></b><th id='zD87j'></th></span></q></dt></tr></i><div id='zD87j'><tfoot id='zD87j'></tfoot><dl id='zD87j'><fieldset id='zD87j'></fieldset></dl></div>
        1. <small id='zD87j'></small><noframes id='zD87j'>

        2. <tfoot id='zD87j'></tfoot>

            <bdo id='zD87j'></bdo><ul id='zD87j'></ul>

                  本文介绍了如何在代码中正确使用 %USERPROFILE%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的代码正确吗?好像可以编译但是不能正常工作..

                  Is my code correct? It seems can compile but does not work properly..

                  CString testing = _T(" --url=") + cstring + _T(" --out=%USERPROFILE%\snapshot.png");
                  

                  我想将它指向用户的文件夹..但仍然无法工作.

                  I want to point it to user's folder..but still cannot work.

                  推荐答案

                  答案是您根本不使用环境变量.相反,您可以使用专门设计用于检索特殊文件夹路径的 shell 函数.

                  The answer is that you don't use environment variables at all. Rather, you use the shell functions specifically designed to retrieve the path of special folders.

                  在 Windows Vista 及更高版本上,该函数是 SHGetKnownFolderPath.它需要 KNOWNFOLDERID 值 来识别要检索其路径的文件夹.在您的情况下,这将是 FOLDERID_Profile.

                  On Windows Vista and later, that function is SHGetKnownFolderPath. It takes KNOWNFOLDERID values to identify the folder whose path you wish to retrieve. In your case, that would be FOLDERID_Profile.

                  如果您需要针对早期版本的 Windows(例如 XP),您将需要使用 SHGetSpecialFolderPath 函数.它需要一个 CSIDL 值来标识您希望检索其路径的文件夹.同样,在您的情况下,这将是 CSIDL_PROFILE.

                  If you need to target earlier versions of Windows (such as XP), you will need to use the SHGetSpecialFolderPath function, instead. It takes a CSIDL value identifying the folder whose path you wish to retrieve. Again, in your case, that would be CSIDL_PROFILE.


                  当然,您不应将数据直接存储在用户的配置文件文件夹中.所以希望您展示的那段代码仅用于演示目的.应用程序应仅在用户配置文件文件夹下的特定位置创建文件, 专为应用程序数据存储而设计.


                  Of course, you should never store data directly in the user's profile folder. So hopefully the bit of code that you've shown is for demonstration purposes only. Applications should only create files in the specific locations under the user profile folder, designed for application data storage.

                  这些位置是 CSIDL_APPDATACSIDL_LOCAL_APPDATA.如果您正在创建用户应该能够修改并视为他/她自己的数据,那么将该数据存储在用户的文档文件夹 (CSIDL_MYDOCUMENTS) 中是合适的.

                  These locations are CSIDL_APPDATA or CSIDL_LOCAL_APPDATA. If you are creating data that the user should be able to modify and should treat as his/her own, then it would be appropriate to store that data in the user's documents folder (CSIDL_MYDOCUMENTS).

                  在my在这里回答.

                  示例代码:

                  TCHAR szFolderPath[MAX_PATH];
                  if (!SHGetSpecialFolderPath(NULL, szFolderPath, CSIDL_APPDATA, FALSE))
                  {
                      // Uh-oh! An error occurred; handle it.
                  }
                  

                  或者,使用 MFC 的 CString 类:

                  Or, using MFC's CString class:

                  CString buffer;
                  BOOL bRet = SHGetSpecialFolderPath(NULL, buffer.GetBuffer(MAX_PATH), CSIDL_APPDATA, FALSE);
                  buffer.ReleaseBuffer();
                  if (!bRet)
                  {
                      // Uh-oh! An error occurred; handle it.
                  }
                  

                  这篇关于如何在代码中正确使用 %USERPROFILE%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                  1. <legend id='jcg7k'><style id='jcg7k'><dir id='jcg7k'><q id='jcg7k'></q></dir></style></legend>

                      <tbody id='jcg7k'></tbody>
                      <bdo id='jcg7k'></bdo><ul id='jcg7k'></ul>

                        <tfoot id='jcg7k'></tfoot>
                        <i id='jcg7k'><tr id='jcg7k'><dt id='jcg7k'><q id='jcg7k'><span id='jcg7k'><b id='jcg7k'><form id='jcg7k'><ins id='jcg7k'></ins><ul id='jcg7k'></ul><sub id='jcg7k'></sub></form><legend id='jcg7k'></legend><bdo id='jcg7k'><pre id='jcg7k'><center id='jcg7k'></center></pre></bdo></b><th id='jcg7k'></th></span></q></dt></tr></i><div id='jcg7k'><tfoot id='jcg7k'></tfoot><dl id='jcg7k'><fieldset id='jcg7k'></fieldset></dl></div>

                            <small id='jcg7k'></small><noframes id='jcg7k'>