Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please how can I get the right LPITEMIDLIST to use for IShellLink::SetIDList?

I tried

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 ) )
            {
                // 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.
Posted
Updated 14-May-13 4:12am
v3
Comments
KarstenK 15-May-13 2:19am    
You must choose the right functions - some are for absolute and some for relative items. So look for it really carefully.

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900