Win 7中的自定义文件属性 [英] Custom File Properties in Win 7
问题描述
在Win Xp等的先前代码中,我设置了一些自定义文件属性,如下面的代码所示.现在,我在Win7中发现这会锁定我的文件,因为pPropSetStg->Release()
失败.但是,进一步,在Win 7上没有自定义文件属性吗?或至少它们不能以相同的方式工作.我找不到任何有关为什么更改它或如何解决它的信息.有谁知道(或链接到)正确的Win7方法来执行此操作?
部分答案...为使您的文件类型显示内置的自定义属性,您需要根据 ^ ].
我添加了注册表项以显示我之后的四个属性,但是,下面的代码仍然不起作用(它将不会释放,并且不会设置指定的属性).
如果我尝试然后在Windows资源管理器中手动编辑属性,则会得到..
发生意外错误,这使您无法将属性应用于文件...
错误0x80004005:未指定的错误"
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"
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;
}
}
推荐答案
好吧,据我所知,在Vista中,NTFS辅助信息流已被完全淘汰.因此,如果要在Win7中使用它,我现在必须开始编写Shell扩展处理程序.
显然,MS认为不适合保持任何中间立场.谢谢你.
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.
这篇关于Win 7中的自定义文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!