从托管代码中的 shell 获取 Vista/Windows Search/propsys.dll 属性
有人设法做到这一点吗? 我尝试为 IPropertyStore 创建一个托管包装类,但在采用指向 PROPVARIANT 的指针的方法(即 IPropertyStore::GetValue)上收到 AccessViolationExceptions(在我的托管版本中呈现为 MarshalAs(UnmanagedType.Struct) 输出参数)可能是我的理解COM 和互操作是不够的 --- 我不确定问题是否出在我的 PROPVARIANT 结构声明中(当前仅使用 StructLayout.Sequential,声明字节序列,并手动操作字节以获取中各种类型的值)联合等),COM 问题涉及哪个进程拥有什么,或者其他什么。 我尝试过各种其他版本的 PROPVARIANT,例如使用 StructLayout.Explicit 进行联合,但没有任何效果。 使用 IPropertyStore::GetAt 检索 PROPERTYKEY --- 它被本地声明为采用指向 PROPERTYKEY 的指针,并在我的包装器中具有我自己的 StructLayout.Sequential PROPERTYKEY 的输出参数 --- 顺便说一句,工作得很好。
Has anyone managed to do this? I tried making a managed wrapper class for IPropertyStore but am getting AccessViolationExceptions on the methods (i.e. IPropertyStore::GetValue) that take a pointer to PROPVARIANT (rendered as a MarshalAs(UnmanagedType.Struct) out parameter in my managed version) Probably my understanding of COM and interop is inadequate --- I'm not sure if the problems are in my PROPVARIANT struct declaration (which currently just uses StructLayout.Sequential, declares a sequence of bytes, and manually manipulates the bytes to get values of the various types in the union etc.), COM issues with what process owns what, or something else. I've tried various other versions of the PROPVARIANT such as using StructLayout.Explicit for the unions, nothing's worked. Retrieving PROPERTYKEYs with IPropertyStore::GetAt --- which is declared natively as taking a pointer to PROPERTYKEY and as having an out parameter of my own StructLayout.Sequential PROPERTYKEY in my wrapper --- works just fine, by the way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这是来自
MS.Internal.Interop
的版本(知识宝库):这些定义将帮助您确保您的结构至少是正确的。 至于你的其他问题,我没有答案。
Well, here's the version from
MS.Internal.Interop
(a trove of knowledge):These definitions will help you make sure your structures are at least correct. As for your other problems, I don't have an answer.
您应该查看 http://code.msdn.microsoft.com/WindowsAPICodePack 。 它支持使用 Windows 属性系统以及许多其他 Windows shell 功能。 我认为这正是您正在寻找的。
You should check out http://code.msdn.microsoft.com/WindowsAPICodePack . It has support for consuming the Windows Property System, and a bunch of other windows shell capabilities. I think it's exactly what you are looking for.