c++ - 路径不存在时的 SHParseDisplayName

标签 c++ winapi windows-shell

我正在开发 IFileOpenDialogIFileSaveDialog 的替代品。

我几乎让它工作(至少 IFileOpenDialog),但是当我想返回代表新文件名(用户选择保存在GetResult() 方法),我无法让 SHParseDisplayName 使用这个新文件名。我总是收到错误 “系统找不到指定的文件”

我会感谢一些示例或其他解决方案来解决我的问题。

编辑:

    HRESULT CFileSaveDialogProxy::GetResult( __RPC__deref_out_opt IShellItem **ppsi)
    {
        //return m_Original->GetResult(ppsi);

        WCHAR pszPath[MAX_PATH] = {0};
        HRESULT hr = ERROR_CANCELLED;

        if (m_SelectedFiles.size() > 0)
        {
            QString s = m_SelectedFiles.at(0);
            s.replace(QString("/"),QString("\\"));
            s.toWCharArray(pszPath);

            //PCIDLIST_ABSOLUTE pIdL = ILCreateFromPath(pszPath);
            PIDLIST_ABSOLUTE pIdL = NULL;
            SFGAOF out;
            hr = SHParseDisplayName(pszPath,NULL,&pIdL,SFGAO_FILESYSTEM,&out);
            if (SUCCEEDED(hr))
            {
                hr = SHCreateItemFromIDList(pIdL, IID_PPV_ARGS(ppsi));
            }
        }

        return hr;
    }

最佳答案

您必须使用 IBindCtx 参数将附加数据传递给解析器,在这种情况下是您自己的文件元数据,因此 SHParseDisplayName() 不会尝试访问真实的文件以获取元数据。这在 IShellFolder::ParseDisplayName() 中有描述。和 SHCreateItemFromParsingName()文档:

A pointer to a bind context used to pass parameters as inputs and outputs to the parsing function. These passed parameters are often specific to the data source and are documented by the data source owners. For example, the file system data source accepts the name being parsed (as a WIN32_FIND_DATA structure), using the STR_FILE_SYS_BIND_DATA bind context parameter. STR_PARSE_PREFER_FOLDER_BROWSING can be passed to indicate that URLs are parsed using the file system data source when possible. Construct a bind context object using CreateBindCtx and populate the values using IBindCtx::RegisterObjectParam. See Bind Context String Keys for a complete list of these.

并在 MSDN“Old New Thing”博客上进行了详细概述:

Creating a simple pidl: For the times you care enough to send the very fake 🕗

关于c++ - 路径不存在时的 SHParseDisplayName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18576103/

相关文章:

c++ - 无法使用 C++ 和 SFML 2.1 将图像文件加载为纹理

.net - Shell 命名空间扩展无法在 Windows 7 中加载

C++:创建模板化的 Shared<T> 对象而不是 shared_ptr<T> 对象

c++ - 如何检查指针是否指向正确对齐的内存位置?

c++ - 如何在ATL/WTL对话框上注册自定义控件?

windows - 强制 IAutoComplete 刷新数据集?

winapi - 在 Windows 7 任务栏中显示完整的应用程序?

winforms - 在 Windows 中更改另一个进程的任务栏图标

c++ - 更好地理解 boost 的聊天客户端示例

c++ - 检测 C++/Win32 中的进程崩溃