none
WPD devices not being returned using Windows Shell (i.e. Windows Explorer) APIs RRS feed

  • Question

  • Hi,

    I ultimately need this code in C# but once I hit this issue, I went back to C++ to see if I could get more details.  

    What I need the code to do is to get the icons of any WPD devices (mainly mobile devices, i.e. Windows Phone, Apple IOS, Android) connected to the Windows computer.  The WPD SDK will not give me the icon so I went to the Shell API.  The functions in the Shell API are a handful to say the least but I thought the code below would give me the WPD objects (in the context of the Shell) and then from the Shell objects, I could figure out how to get the icons.  Well, the code below does not return the WPD objects, just the disk drives.  Does anyone have any advice (or working code :-) ) on how I can get the icons of the WPD devices/objects from the Shell API or in the very least how to obtain the Shell object that represent the WPD devices/objects?  Thanks very much in advance.  

    #include "stdafx.h"

    int _tmain(int argc, _TCHAR* argv[])
    {
    HRESULT l_HRESULT = S_OK;
    IShellFolder* l_pIShellFolderDesktopFolder = NULL;

    l_HRESULT = SHGetDesktopFolder(&l_pIShellFolderDesktopFolder);

        if ((SUCCEEDED(l_HRESULT)) &&
    (l_pIShellFolderDesktopFolder != NULL))
        {
    PIDLIST_ABSOLUTE l_PIDLIST_ABSOLUTEComputer = NULL;

    l_HRESULT = SHGetSpecialFolderLocation(NULL, 
      CSIDL_DRIVES, //should get us ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} 
      &l_PIDLIST_ABSOLUTEComputer);

    if ((SUCCEEDED(l_HRESULT)) &&
    (l_PIDLIST_ABSOLUTEComputer != NULL))
    {
            IShellFolder* l_IShellFolderComputer = NULL;

    l_HRESULT = 
    l_pIShellFolderDesktopFolder->BindToObject(
    l_PIDLIST_ABSOLUTEComputer, 
    NULL, 
    IID_PPV_ARGS(&l_IShellFolderComputer));

                if ((SUCCEEDED(l_HRESULT)) &&
    (l_IShellFolderComputer != NULL))
    {
    IEnumIDList* l_pIEnumIDList = NULL;
       DWORD l_DWORDSHCONTFFlags = SHCONTF_CHECKING_FOR_CHILDREN |
    SHCONTF_FOLDERS |
    SHCONTF_NONFOLDERS |
    SHCONTF_INCLUDEHIDDEN |
    //SHCONTF_INIT_ON_FIRST_NEXT |
    //SHCONTF_NETPRINTERSRCH |
    SHCONTF_SHAREABLE |
    SHCONTF_STORAGE |
    SHCONTF_NAVIGATION_ENUM |
    SHCONTF_FASTITEMS |
    SHCONTF_FLATLIST |
    SHCONTF_ENABLE_ASYNC |
    SHCONTF_INCLUDESUPERHIDDEN;
    l_HRESULT =
                    l_IShellFolderComputer->EnumObjects(NULL,
                                                        l_DWORDSHCONTFFlags,
                                                        &l_pIEnumIDList);

    if ((SUCCEEDED(l_HRESULT)) &&
    (l_pIEnumIDList != NULL))
    {
    LPITEMIDLIST childItemID = NULL;
    while (S_OK == l_pIEnumIDList->Next(1, &childItemID, NULL)) 
    {
    STRRET strRetItemName;

    l_HRESULT = l_IShellFolderComputer->
    GetDisplayNameOf(childItemID, 
    SHGDN_FORPARSING, 
    &strRetItemName);
    if (SUCCEEDED(l_HRESULT))
    {
    OutputDebugString(strRetItemName.pOleStr);
    _tprintf(_T("%s\n"), strRetItemName.pOleStr);
    }
    }
    }

    l_IShellFolderComputer->Release();
    }

           CoTaskMemFree(l_PIDLIST_ABSOLUTEComputer);
    }
        }

    return 0;
    }


    Anthony LaMark

    Wednesday, May 7, 2014 11:52 PM

All replies

  • Hi,

    In order to provide better support, I help you move this thread to Windows Hardware WDK and Driver Development forum. Hope you can understand.

    Best Regards,

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 8, 2014 6:09 AM
  • Hi Anthony,

    When you say you were unable to get the icons of any WPD devices connected to the computer, what WPD APIs did you call?

    WPD devices that provide icons do have the icon data available as a WPD_RESOURCE_ICON on the device object.  You can use IPortableDeviceResource from C++ to get the icon data as an IStream.

    lisa

     

    Thursday, May 8, 2014 8:00 PM
  • Hi Lisa,

    Thanks for replying...I thought for sure this one would rot on the vine! :-)

    I was/am initially trying to go thru the Windows Explorer (i.e. Shell) APIs to get at the icons since my ultimate goal is back in C# (Winform app) where I can (hopefully using common code) get the icons for not only the WPD devices but also the icons of other storage devices (local and networked drives).  The documentation implies that this is possible but the execution of the code does not show this.

    If the WPD API is the only route then I will do that.  Thanks for the WPD_RESOURCE_ICON tip.  

    So, if there is a possibility that I can use the Shell API to get at the WPD icons, I am interested to hear if that is possible.  If no, I will code using the WPD API.

    Thanks again for responding, I really appreciate it.


    Anthony LaMark

    Thursday, May 8, 2014 8:16 PM