Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is some code I've inherited in my job:

public string GetProperty(SummaryPropId summaryPropertID)
{
    IPropertySetStorage pssSetStorage = null;
    Guid guidPropertySetStorage = new Guid("0000013A-0000-0000-C000-000000000046");
    Guid guidSummaryProperties = new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9");
    IPropertyStorage psStorage = null;
    PropSpec[] pscSpecs = new PropSpec[1];
    PropVariant[] pvValues = new PropVariant[1];

    try
    {
        //Exit if file does not exist
        if (!fiSource.Exists) return null;
        // Open the file and its property set stream
        uint hresult = ole32.StgOpenStorageEx(fiSource.FullName, (int)(STGM.DIRECT_SWMR | STGM.READ | STGM.SHARE_DENY_NONE), (int)STGFMT.FILE, 0, System.IntPtr.Zero, System.IntPtr.Zero, ref guidPropertySetStorage, ref pssSetStorage);
        // Open the Summary Information property set
        int hresult2 = pssSetStorage.Open(ref guidSummaryProperties, (int)(STGM.DIRECT | STGM.SHARE_EXCLUSIVE), out psStorage);
        // Specify the property to be retrieved
        pscSpecs[0].ulKind = 1;
        pscSpecs[0].Name_Or_ID = new IntPtr((int)summaryPropertID);
        // Retrieve the value
        hresult2 = psStorage.ReadMultiple(1, pscSpecs, pvValues);
        // Release the Com objects
        Marshal.ReleaseComObject(psStorage);
        Marshal.ReleaseComObject(pssSetStorage);
        psStorage = null;
        pssSetStorage = null;
    }
    catch (Exception excException)
    {
        AuditMethodError(excException, System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " - " + excException.StackTrace);
    }
    finally
    {
        pssSetStorage = null;
        psStorage = null;
        pscSpecs = null;
        pvValues = null;
    }
    return Marshal.PtrToStringUni(pvValues[0].pointerValue);
}


The problem is that when it gets to the line int hresult2 = pssSetStorage.Open(ref guidSummaryProperties, (int)(STGM.DIRECT | STGM.SHARE_EXCLUSIVE), out psStorage) I'm receiving this exception:

excException = {"Object reference not set to an instance of an object."}

Here is my interface declaration:

C#
[ComVisible(true), ComImport(), Guid("0000013A-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPropertySetStorage
{
    uint Create([In] ref System.Guid rfmtid, [In] IntPtr pclsid, [In] int grfFlags, [In] int grfMode, ref IPropertyStorage propertyStorage);
    int Open([In] ref System.Guid rfmtid, [In] int grfMode, [Out] out IPropertyStorage propertyStorage);
}


Here is my STGM enumeration:

C#
public enum STGM : int
{
    READ = 0x00000000,
    WRITE = 0x00000001,
    READWRITE = 0x00000002,
    SHARE_DENY_NONE = 0x00000040,
    SHARE_DENY_READ = 0x00000030,
    SHARE_DENY_WRITE = 0x00000020,
    SHARE_EXCLUSIVE = 0x00000010,
    PRIORITY = 0x00040000,
    CREATE = 0x00001000,
    CONVERT = 0x00020000,
    FAILIFTHERE = 0x00000000,
    DIRECT = 0x00000000,
    TRANSACTED = 0x00010000,
    NOSCRATCH = 0x00100000,
    NOSNAPSHOT = 0x00200000,
    SIMPLE = 0x08000000,
    DIRECT_SWMR = 0x00400000,
    DELETEONRELEASE = 0x04000000
}


Does anyone have any suggestions?
Posted

I've never used it, but I found a ton of examples with a simple Google for "C# IPropertySetStorage".
 
Share this answer
 
I'm going to download http://code.msdn.microsoft.com/WindowsAPICodePack
and research the "Shell Property System" instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900