如何获得正确的LPITEMIDLIST用于IShellLink :: SetIDList [英] How to get the right LPITEMIDLIST to use for IShellLink::SetIDList

查看:144
本文介绍了如何获得正确的LPITEMIDLIST用于IShellLink :: SetIDList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问如何获得用于IShellLink :: SetIDList的正确LPITEMIDLIST?



我试过



<前lang =c ++> HRESULT hr = S_OK;
ULONG celtFetched;
LPITEMIDLIST pidlItems = NULL;
LPITEMIDLIST netItemIdLst = NULL;
IShellFolder * pPrinterFolder = NULL;
IEnumIDList * pEnumIds = NULL;
IMalloc * pMalloc = NULL;
IShellFolder * pDesktopFolder = NULL;
CoInitializeEx(NULL, 0 );
hr = SHGetMalloc(& pMalloc);
hr = SHGetDesktopFolder(& pDesktopFolder);
hr = SHGetSpecialFolderLocation(NULL,CSIDL_PRINTERS,& netItemIdLst);
hr = pDesktopFolder-> BindToObject(netItemIdLst,NULL,IID_IShellFolder,( void **)& pPrinterFolder);

if (SUCCEEDED(hr))
{
hr = pPrinterFolder-> EnumObjects(NULL,SHCONTF_NONFOLDERS, & pEnumIds);
if (SUCCEEDED(hr))
{
STRRET strDisplayName;
while ((hr = pEnumIds-> Next( 1 ,& pidlItems,& ; celtFetched))== S_OK&& celtFetched> 0
{
hr = pPrinterFolder-> GetDisplayNameOf(pidlItems,SHGDN_NORMAL ,& strDisplayName);
if (SUCCEEDED(hr))
{
// 使用了phelllItems for IShellLink :: SetIDList
}
}
}
}





但这导致一个空白的快捷方式(即快捷方式没有指向任何地方)。



编辑:

现在刚刚了解到枚举中的pidlItems是相对的,但SetIDList需要一个绝对的LPITEMIDLIST。如何将pidlItem转为绝对值。

解决方案

最后得到它...

由于 netItemIdLst 指向打印机文件夹, pidlItems 是打印机项的相对部分, pidlItems 是被附加到 netItemIdLst 以获得绝对路径。



http://www.netpatch.ru/misc-files/create_shortcut.cpp.html [ ^ ]


Please how can I get the right LPITEMIDLIST to use for IShellLink::SetIDList?

I tried

HRESULT hr = S_OK;
ULONG celtFetched;
LPITEMIDLIST pidlItems = NULL;
LPITEMIDLIST netItemIdLst = NULL;
IShellFolder* pPrinterFolder = NULL;
IEnumIDList* pEnumIds = NULL;
IMalloc* pMalloc = NULL;
IShellFolder* pDesktopFolder = NULL;
CoInitializeEx( NULL, 0 );
hr = SHGetMalloc( &pMalloc );
hr = SHGetDesktopFolder( &pDesktopFolder );
hr = SHGetSpecialFolderLocation( NULL, CSIDL_PRINTERS, &netItemIdLst );
hr = pDesktopFolder->BindToObject( netItemIdLst, NULL, IID_IShellFolder, (void **)&pPrinterFolder );

if ( SUCCEEDED( hr ) )
{
    hr = pPrinterFolder->EnumObjects( NULL, SHCONTF_NONFOLDERS, &pEnumIds );
    if ( SUCCEEDED( hr ) )
    {
        STRRET strDisplayName;
        while ( ( hr = pEnumIds->Next( 1, &pidlItems, &celtFetched ) ) == S_OK && celtFetched > 0 )
        {
            hr = pPrinterFolder->GetDisplayNameOf( pidlItems, SHGDN_NORMAL, &strDisplayName );
            if ( SUCCEEDED( hr ) )
            {
                // used pidlItems for the IShellLink::SetIDList
            }
         }
      }
}



But this result in a blank shortcut (i.e. the shortcut wasn''t pointing to anywhere).

EDIT:
Just learnt now that the pidlItems gotten from the enumeration is relative but SetIDList require an absolute LPITEMIDLIST. How can pidlItems be turned to absolute.

解决方案

Got it finally...
Since netItemIdLst is pointing to the Printer Folder and pidlItems is the relative part to a Printer Item, pidlItems is to be appended to netItemIdLst to get the absolute path.

http://www.netpatch.ru/misc-files/create_shortcut.cpp.html[^]


这篇关于如何获得正确的LPITEMIDLIST用于IShellLink :: SetIDList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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