Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3665400
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:45:24+00:00 2026-05-19T01:45:24+00:00

I’m working on a drag and drop problem now and trying to get the

  • 0

I’m working on a drag and drop problem now and trying to get the PIDLs of the items being dragged from windows shell to my application.

The code below can get correct PIDLs if the dragged item is ‘My Computer’ or ‘Control Panel’ itself, but it doesn’t work when the dragged item is an item in the ‘Control Panel’.

What’s wrong with my code?


#define GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])
#define GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])

STGMEDIUM medium;

UINT fmt = RegisterClipboardFormat(CFSTR_SHELLIDLIST);
FORMATETC fe= {fmt, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
HRESULT GETDATA_RESULT = pDataObject->GetData(&fe, &medium);

if (SUCCEEDED(GETDATA_RESULT))
{
    LPIDA pida = (LPIDA)GlobalLock(medium.hGlobal);
    LPCITEMIDLIST pidlFolder = GetPIDLFolder(pida);

    int n = pida->cidl;  // the n is always correct
    if( n > 0 )
    {
        LPCITEMIDLIST pidlItem = GetPIDLItem(pida, 0);
        // the pidlItem is wrong when the dragged object is an item in 'Control Panel'
    }

    GlobalUnlock(medium.hGlobal);
}
ReleaseStgMedium(&medium);

Any idea? Thanks

Zach@Shine

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:45:25+00:00Added an answer on May 19, 2026 at 1:45 am

    If I D&D Mouse, Network Connections and Fonts I get the following output in my test app:

    • 0 Mouse | sfgao=4 hr=0
    • 1 ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E} | sfgao=20000004 hr=0
    • 2 C:\WINDOWS\Fonts | sfgao=60000004 hr=0

    The Network Connections and Fonts pidls can be converted to fully qualified shell paths while Mouse only returns a relative path/displayname.
    This makes sense if you check the documentation for IShellFolder::GetDisplayNameOf:

    …They do not guarantee that
    IShellFolder will return the requested
    form of the name. If that form is not
    available, a different one might be
    returned. In particular, there is no
    guarantee that the name returned by
    the SHGDN_FORPARSING flag will be
    successfully parsed by
    IShellFolder::ParseDisplayName. There
    are also some combinations of flags
    that might cause the
    GetDisplayNameOf/ParseDisplayName
    round trip to not return the original
    identifier list. This occurrence is
    exceptional, but you should check to
    be sure.

    It is clear that when dealing with controlpanel items, you need to keep the pidl around and only use GetDisplayNameOf for display strings in your UI.
    (IShellLink::SetIDList on the Mouse pidl will create a working shortcut so the pidl is valid)

    void OnDrop(IDataObject*pDO) 
    {
        STGMEDIUM medium;
        UINT fmt = RegisterClipboardFormat(CFSTR_SHELLIDLIST);
        FORMATETC fe= {fmt, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
        HRESULT hr = pDO->GetData(&fe, &medium);
        if (SUCCEEDED(hr)) 
        {
            LPIDA pida = (LPIDA)GlobalLock(medium.hGlobal);
            if (pida) 
            {
                LPCITEMIDLIST pidlFolder = GetPIDLFolder(pida);
                for (UINT i=0; i<pida->cidl; ++i) 
                {
                    LPCITEMIDLIST pidlItem = GetPIDLItem(pida,i);
                    LPITEMIDLIST pidlAbsolute = ILCombine(pidlFolder,pidlItem);
                    if (pidlAbsolute) 
                    {
                        IShellFolder*pParentSF;
                        hr= SHBindToParent(pidlAbsolute,IID_IShellFolder,(void**)&pParentSF,&pidlItem);
                        if (SUCCEEDED(hr))
                        {
                            STRRET str; 
                            hr= pParentSF->GetDisplayNameOf(pidlItem, SHGDN_FORPARSING, &str);
                            if (SUCCEEDED(hr))
                            {
                                TCHAR szName[MAX_PATH];
                                hr= StrRetToBuf(&str,pidlItem,szName,MAX_PATH);
                                if (SUCCEEDED(hr)) 
                                {
                                    SFGAOF sfgao = SFGAO_FOLDER|SFGAO_FILESYSTEM|SFGAO_HASSUBFOLDER|SFGAO_CANLINK;
                                    hr= pParentSF->GetAttributesOf(1,&pidlItem,&sfgao);
                                    TRACE(_T("%u %s | sfgao=%X hr=%X\n"),i,szName,sfgao,hr);
                                    CreateTestShortcut(pidlAbsolute);
                                }
                            }
                            pParentSF->Release();
                        }
                        ILFree(pidlAbsolute);
                    }
                }
                GlobalUnlock(medium.hGlobal);
            }
            ReleaseStgMedium(&medium);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.