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?
EDIT:
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"
USES_CONVERSION;
WCHAR wcFilename[1024];
IStorage *pStorage = NULL;
IPropertyStorage *pPropStg = NULL;
IPropertySetStorage *pPropSetStg = NULL;
PROPSPEC propspec[4];
PROPVARIANT propvarWrite[4];
HRESULT hr;
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)
{
hr = pPropSetStg->Create(fmtid, NULL, PROPSETFLAG_DEFAULT, STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &pPropStg);
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;
}
}