Persist a pidl (ITEMIDLIST)

前端 未结 3 1812
长情又很酷
长情又很酷 2021-01-12 17:16

I\'d like to persist pidls between sessions, so that my application can remember the users\' folder selections, wherever they may be in the namespace, even if they\'re not f

相关标签:
3条回答
  • 2021-01-12 17:30

    According to Raymond Chen you can persist a pidl -- or, more specifically, a SHITEMID structure, just by writing out length of the item and then the bytes.

    Notice that this struct is a typical Windows variable length struct, with a cb ("count of bytes") element specifying the length of the structure in bytes, followed by the rest of the data. In other words, to write the structure, you need to write cb bytes. To read it, you need to allocated cb bytes of memory and set the cb field.

    Be careful not to use sizeof(SHITEMID) because the way it's declared assumes only one byte for the abID field so that won't be big enough.

    0 讨论(0)
  • 2021-01-12 17:35

    ILSaveToStream and ILLoadFromStream (and possibly ILLoadFromStreamEx). There is one caveat though: ILLoadFromStream and ILLoadFromStreamEx are deprecated, and if Microsoft has said what's supposed to replace them, I'm not aware of it.

    0 讨论(0)
  • 2021-01-12 17:45

    There isn't standard on the internal of pidls. After all, pidl is only used to locate items. As long as the pidl is recognized (or fail predictably) by the PIDL generator & resolver (Windows Explorer or third party shell namespace extensions), Explorer.exe is happy. Nobody says a PIDL must be persistable across machine reboots or user desktops.

    In one case you can make an educated guess if the pidl is persistable across machine reboots is to check the SFGAO_CANLINK attribute. By declaring this attribute, the PIDL resolver declares you can drag an item in the folder to create a desktop shortcut which contains the PIDL of the item. The resolver must handle persistence and backward compatibility in the PIDL otherwise double clicking the shortcut would crash the Explorer process. Buggy programming happens so don't take this for granted.

    In the dark old days pidl are just persisted in byte arrays, or when passing across COM objects are needed, passed in VARIANT as safe arrays of bytes.

    0 讨论(0)
提交回复
热议问题