Click here to Skip to main content
15,846,342 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In previous code for Win Xp etc I set some custom file properties as in the code below. I now find in Win7 that this locks my file because the pPropSetStg->Release() fails. But further, on Win 7 there are no custom file properties? Or at least they don't work in the same way. I can't find anything about why this was changed or how to get around it. Does anyone know (or have a link to) the proper Win7 way to do this?


A partial answer... to make the built in custom properties appear for your file type, you neeed to add a registry key as per System Supplied Property Handlers[^].

I added the registry entry to display the four properties I'm after, however, the code below still doesn't work (it won't release, and doesn't set the specified properties).

If I try then to edit the properties manually in Windows Explorer, I get..

"An unexpected error is keeping you from applying properties to the file...

Error 0x80004005: Unspecified Error"

WCHAR wcFilename[1024];
IStorage *pStorage = NULL;
IPropertyStorage *pPropStg = NULL;
IPropertySetStorage *pPropSetStg = NULL;
PROPSPEC propspec[4];
PROPVARIANT propvarWrite[4];
IID riid;

const FMTID fmtid = FMTID_SummaryInformation;
const int MAX_BIG_STRING_LEN = 1024;

setlocale(LC_ALL, "");
size_t i = mbstowcs(wcFilename, newName, strlen(newName));
setlocale(LC_ALL, "C");
wcFilename[i] = 0;

riid = IID_IPropertySetStorage;

hr = StgOpenStorageEx(wcFilename, STGM_READ|STGM_SHARE_DENY_WRITE, STGFMT_FILE, 0, NULL, NULL, riid, (void **)(&pStorage));
if (!FAILED(hr) && pStorage != NULL)
    hr = pStorage->QueryInterface(riid, (void **)&pPropSetStg);
    if (!FAILED(hr) && pPropSetStg != NULL)

        if (!FAILED(hr) && pPropStg != NULL)
            propspec[0].ulKind = PRSPEC_PROPID;
            propspec[0].propid = PIDSI_TITLE;
            propvarWrite[0].vt = VT_LPWSTR;
            propvarWrite[0].pwszVal = A2W(MyTitle);

            propspec[1].ulKind = PRSPEC_PROPID;
            propspec[1].propid = PIDSI_SUBJECT;
            propvarWrite[1].vt = VT_LPWSTR;
            propvarWrite[1].pwszVal = A2W(MyDescription);

            propspec[2].ulKind = PRSPEC_PROPID;
            propspec[2].propid = PIDSI_AUTHOR;
            propvarWrite[2].vt = VT_LPWSTR;
            propvarWrite[2].pwszVal = A2W(MyAuthor);

            propspec[3].ulKind = PRSPEC_PROPID;
            propspec[3].propid = PIDSI_COMMENTS;
            propvarWrite[3].vt = VT_LPWSTR;
            propvarWrite[3].pwszVal = A2W(MyComments);

            hr = pPropStg->WriteMultiple(4, propspec, propvarWrite, NULL);
            if (!FAILED(hr))
                hr = pPropStg->Commit(STGC_DEFAULT);

            hr = pPropStg->Release();
            pPropStg = NULL;

        hr = pPropSetStg->Release();
        pPropSetStg = NULL;
Updated 12-Aug-12 14:45pm
barneyman 12-Aug-12 21:39pm    
your code doesn't show you Commit'ing and Release'ing pStorage - I assume you are?
Kyudos 12-Aug-12 23:26pm    
Actually, I wasn't.. but the likely outcome is I'll take it out completely until I can develop a robust solution that works on XP, Vista and Seven

1 solution

Well, as far as I can Google, NTFS secondary info streams were completely ditched in Vista. So if I want this to work in Win7 I now have to start writing shell extension handlers.

Apparently MS didn't see fit to keep any sort of middle ground. Thanks for that.
Share this answer
barneyman 12-Aug-12 23:34pm    
SE's aren't that bad :) and do yourself a favour, start using CComPtr(and CComQIPtr) to wrap those interfaces - much easier on the eye
Kyudos 13-Aug-12 0:45am    
I suppose the question remains, and I'm not quite sure about this, DO I need a shell extension? I only want to set these four 'default' PIDSI values when I save my files. Is there no way that Windows 7 can set and show them without any messing? I don't need to be able to edit the properties in Windows Explorer - just see them.

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