Getting Vista / Windows Search / propsys.dll properties from shell in managed code
Has anyone been able to do this? I tried to create a managed wrapper class for IPropertyStore, but I get AccessViolationExceptions for methods (like IPropertyStore :: GetValue) that take a pointer to PROPVARIANT (displayed as MarshalAs (UnmanagedType.Struct) parameter in my managed version). Perhaps my understanding of COM and interop is inadequate --- I'm not sure if the problems are in my declaration of the PROPVARIANT structure (which currently just uses StructLayout.Sequential, declares a sequence of bytes and manually manipulates bytes to get values ββof various types into union, etc.) , COM problems with which process belongs what or something else. I have tried other versions of PROPVARIANT such as using StructLayout.Explicit for unions, nothing worked.Getting PROPERTYKEYs using IPropertyStore :: GetAt --- which is declared initially to take a pointer to PROPERTYKEY and has an out parameter from my own StructLayout.Sequential PROPERTYKEY in my wrapper --- works great by the way.
source to share
You have to check http://code.msdn.microsoft.com/WindowsAPICodePack . It supports the use of the Windows property system and many other features of the Windows shell. I think this is exactly what you are looking for.
source to share
Well, here's the version from MS.Internal.Interop
(sword 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 ensure that your structures are at least correct. As for your other problems, I have no answer.
source to share