路径不存在时的SHParseDisplayName [英] SHParseDisplayName when path doesn't exists

查看:556
本文介绍了路径不存在时的SHParseDisplayName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 IFileOpenDialog IFileSaveDialog 的替代品。

I'm developing a replacement for IFileOpenDialog and IFileSaveDialog.

我几乎有工作(至少 IFileOpenDialog ),但是当我要返回 IShellItem 表示新的文件名(用户选择保存在 GetResult()方法中),我不能得到 SHParseDisplayName 使用此新文件名。我总是收到一个错误系统找不到指定的文件

I almost have it working (at least IFileOpenDialog), but when I want to return the IShellItem that represents the new filename (that the user has choosen to save in the GetResult() method), I can't get SHParseDisplayName working with this new filename. I always receive an error "The system cannot find the file specified".

我会感谢一些例子或另一个解决方案也许对我的问题。

I will appreciate some examples or another solution maybe to my problem.

编辑:

    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;
    }


推荐答案

code> IBindCtx 参数传递额外的数据到解析器,在这种情况下你自己的文件元数据,所以 SHParseDisplayName()不会尝试访问一个真实的文件来获取元数据。这在 IShellFolder :: ParseDisplayName中有所描述() SHCreateItemFromParsingName() 文档:

You have to use the IBindCtx parameter to pass additional data to the parser, in this case your own file metadata so SHParseDisplayName() will not try to access a real file to get the metadata. This is described in the IShellFolder::ParseDisplayName() and SHCreateItemFromParsingName() documentations:


以将参数作为输入和输出传递给解析函数。这些传递的参数通常特定于数据源,并由数据源所有者记录。 例如,文件系统数据源接受要解析的名称(作为 WIN32_FIND_DATA 结构),使用 STR_FILE_SYS_BIND_DATA 绑定上下文参数。可以传递STR_PARSE_PREFER_FOLDER_BROWSING以指示在可能的情况下使用文件系统数据源解析网址。 使用 CreateBindCtx 构建绑定上下文对象,使用 IBindCtx :: RegisterObjectParam 填充值。有关这些列表的完整列表,请参见绑定上下文字符串

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的旧新事物博客中详细介绍:

And outlined in detail on the MSDN "Old New Thing" blog:

创建简单的pidl:For你关心的时间足以发送非常假的

这篇关于路径不存在时的SHParseDisplayName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆