<tfoot id='mEfvI'></tfoot>

    <legend id='mEfvI'><style id='mEfvI'><dir id='mEfvI'><q id='mEfvI'></q></dir></style></legend>

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

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

        windows在c++中读取快捷方式文件的目标

        时间:2023-07-19

            <i id='0aU6r'><tr id='0aU6r'><dt id='0aU6r'><q id='0aU6r'><span id='0aU6r'><b id='0aU6r'><form id='0aU6r'><ins id='0aU6r'></ins><ul id='0aU6r'></ul><sub id='0aU6r'></sub></form><legend id='0aU6r'></legend><bdo id='0aU6r'><pre id='0aU6r'><center id='0aU6r'></center></pre></bdo></b><th id='0aU6r'></th></span></q></dt></tr></i><div id='0aU6r'><tfoot id='0aU6r'></tfoot><dl id='0aU6r'><fieldset id='0aU6r'></fieldset></dl></div>
              <tbody id='0aU6r'></tbody>
            <legend id='0aU6r'><style id='0aU6r'><dir id='0aU6r'><q id='0aU6r'></q></dir></style></legend>
          • <tfoot id='0aU6r'></tfoot>

            • <small id='0aU6r'></small><noframes id='0aU6r'>

                <bdo id='0aU6r'></bdo><ul id='0aU6r'></ul>
                1. 本文介绍了windows在c++中读取快捷方式文件的目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在windows上读取快捷方式文件的目标.尝试使用 boost::read_symlink 抛出异常,说文件或目录不是重新解析点"消息.

                  How to read the target of shortcut file on windows. Tried using boost::read_symlink which throws exception saying "the file or directory is not a reparse point" message.

                  int main(int argc, _TCHAR* argv[])
                  {           
                      try {
                      boost::filesystem::path target = boost::filesystem::read_symlink("c:\tmp\blobstore_2.lnk");
                      cout<<target.string();
                      } catch(const boost::filesystem::filesystem_error& ex)
                      {
                          cout<<"in catch"<<ex.what(); // prints "the file or directory is not a reparse point"
                      }
                  
                      std::ifstream smbConfStream("c:\tmp\sym_file_2.lnk");
                      string ss((std::istreambuf_iterator<char>(smbConfStream)),
                          std::istreambuf_iterator<char>());
                      cout <<endl<<" ss: "<<ss; // From the output of the "ss" it looks like the information of the target is present inside ss along with other binary data. How to cleanly get the target out.
                  
                      int i;
                      cin>>i;
                  
                      return 0;
                  }
                  

                  推荐答案

                  Windows .lnk 文件不是符号链接.它是一个快捷方式文件.您可以使用 IShellLink 界面来操作它.

                  A Windows .lnk file is not a symbolic link. It is a shortcut file. You use the IShellLink interface to manipulate it.

                  文档 包含以下示例,演示如何解析快捷方式文件.

                  The documentation contains the following example demonstrating how to resolve a shortcut file.

                  // ResolveIt - Uses the Shell's IShellLink and IPersistFile interfaces 
                  //             to retrieve the path and description from an existing shortcut. 
                  //
                  // Returns the result of calling the member functions of the interfaces. 
                  //
                  // Parameters:
                  // hwnd         - A handle to the parent window. The Shell uses this window to 
                  //                display a dialog box if it needs to prompt the user for more 
                  //                information while resolving the link.
                  // lpszLinkFile - Address of a buffer that contains the path of the link,
                  //                including the file name.
                  // lpszPath     - Address of a buffer that receives the path of the link
                                    target, including the file name.
                  // lpszDesc     - Address of a buffer that receives the description of the 
                  //                Shell link, stored in the Comment field of the link
                  //                properties.
                  
                  #include "stdafx.h"
                  #include "windows.h"
                  #include "shobjidl.h"
                  #include "shlguid.h"
                  #include "strsafe.h"
                  
                  HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPWSTR lpszPath, int iPathBufferSize) 
                  { 
                      HRESULT hres; 
                      IShellLink* psl; 
                      WCHAR szGotPath[MAX_PATH]; 
                      WCHAR szDescription[MAX_PATH]; 
                      WIN32_FIND_DATA wfd; 
                  
                      *lpszPath = 0; // Assume failure 
                  
                      // Get a pointer to the IShellLink interface. It is assumed that CoInitialize
                      // has already been called. 
                      hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); 
                      if (SUCCEEDED(hres)) 
                      { 
                          IPersistFile* ppf; 
                  
                          // Get a pointer to the IPersistFile interface. 
                          hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); 
                  
                          if (SUCCEEDED(hres)) 
                          { 
                              WCHAR wsz[MAX_PATH]; 
                  
                              // Ensure that the string is Unicode. 
                              MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH); 
                  
                              // Add code here to check return value from MultiByteWideChar 
                              // for success.
                  
                              // Load the shortcut. 
                              hres = ppf->Load(wsz, STGM_READ); 
                  
                              if (SUCCEEDED(hres)) 
                              { 
                                  // Resolve the link. 
                                  hres = psl->Resolve(hwnd, 0); 
                  
                                  if (SUCCEEDED(hres)) 
                                  { 
                                      // Get the path to the link target. 
                                      hres = psl->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA*)&wfd, SLGP_SHORTPATH); 
                  
                                      if (SUCCEEDED(hres)) 
                                      { 
                                          // Get the description of the target. 
                                          hres = psl->GetDescription(szDescription, MAX_PATH); 
                  
                                          if (SUCCEEDED(hres)) 
                                          {
                                              hres = StringCbCopy(lpszPath, iPathBufferSize, szGotPath);
                                              if (SUCCEEDED(hres))
                                              {
                                                  // Handle success
                                              }
                                              else
                                              {
                                                  // Handle the error
                                              }
                                          }
                                      }
                                  } 
                              } 
                  
                              // Release the pointer to the IPersistFile interface. 
                              ppf->Release(); 
                          } 
                  
                          // Release the pointer to the IShellLink interface. 
                          psl->Release(); 
                      } 
                      return hres; 
                  }
                  

                  这篇关于windows在c++中读取快捷方式文件的目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:你能在 boost asio 中设置 SO_RCVTIMEO 和 SO_SNDTIMEO 套接字选项吗? 下一篇:加强宣传 - 需要帮助

                  相关文章

                2. <legend id='1Zq3s'><style id='1Zq3s'><dir id='1Zq3s'><q id='1Zq3s'></q></dir></style></legend>

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

                        <bdo id='1Zq3s'></bdo><ul id='1Zq3s'></ul>
                    1. <tfoot id='1Zq3s'></tfoot>

                      <small id='1Zq3s'></small><noframes id='1Zq3s'>