Freigeben über


Getting the Printer Friendly name from the Device Center shell folder

If you are writing a context menu for the device center, you will probably need to get the "canonical" or "friendly" name of the printer or device that the user has right-clicked on. While your context menu extension gets passed a data object that should contain this information, it unfortunately doesn't. However, here's some code that should help you achieve this. Please note this code is for illustration purposes only and is not ready to be put in a production environment, use at your own risk, etc. :-)

Enjoy!!

    IShellItemArray *psa;

    if (SUCCEEDED(SHCreateShellItemArrayFromDataObject(pdtobj, IID_PPV_ARGS(&psa))))

    {

        IShellItem *psi;

        if (SUCCEEDED(psa->GetItemAt(0, &psi)))

        {

            IShellItem2 *psi2;

            if (SUCCEEDED(psi->QueryInterface(IID_PPV_ARGS(&psi2))))

            {

                if (SUCCEEDED(psi2->GetProperty(PKEY_Devices_InterfacePaths, &pv)))

                {

                    if (pv.vt == (VT_ARRAY | VT_LPWSTR))

                    {

                        for (unsigned int i = 0; i < pv.calpwstr.cElems; i++)

                        {

                            MessageBox(NULL, pv.calpwstr.pElems[i], L“Interface path”, MB_OK); // <-- this will give something like {GUID},CanonicalName

                        }

            }

            }

           }

        }

    }