从托管代码中的 shell 获取 Vista/Windows Search/propsys.dll 属性

发布于 2024-07-10 01:41:55 字数 534 浏览 8 评论 0原文

有人设法做到这一点吗? 我尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看海 2024-07-17 01:42:02

好吧,这是来自 MS.Internal.Interop 的版本(知识宝库):

[StructLayout(LayoutKind.Sequential), FriendAccessAllowed]
internal struct PROPVARIANT
{
    internal VARTYPE vt;
    internal ushort wReserved1;
    internal ushort wReserved2;
    internal ushort wReserved3;
    internal PropVariantUnion union;
}

[FriendAccessAllowed]
internal enum VARTYPE : short
{
    VT_BSTR = 8,
    VT_FILETIME = 0x40,
    VT_LPSTR = 30,
    // etc...
}


[StructLayout(LayoutKind.Explicit), FriendAccessAllowed]
internal struct PropVariantUnion
{
    [FieldOffset(0)]
    internal BLOB blob;
    [FieldOffset(0)]
    internal short boolVal;
    // etc... see MS.Internal.Interop for full definition
}

这些定义将帮助您确保您的结构至少是正确的。 至于你的其他问题,我没有答案。

Well, here's the version from MS.Internal.Interop (a trove of knowledge):

[StructLayout(LayoutKind.Sequential), FriendAccessAllowed]
internal struct PROPVARIANT
{
    internal VARTYPE vt;
    internal ushort wReserved1;
    internal ushort wReserved2;
    internal ushort wReserved3;
    internal PropVariantUnion union;
}

[FriendAccessAllowed]
internal enum VARTYPE : short
{
    VT_BSTR = 8,
    VT_FILETIME = 0x40,
    VT_LPSTR = 30,
    // etc...
}


[StructLayout(LayoutKind.Explicit), FriendAccessAllowed]
internal struct PropVariantUnion
{
    [FieldOffset(0)]
    internal BLOB blob;
    [FieldOffset(0)]
    internal short boolVal;
    // etc... see MS.Internal.Interop for full definition
}

These definitions will help you make sure your structures are at least correct. As for your other problems, I don't have an answer.

溺渁∝ 2024-07-17 01:42:01

您应该查看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文