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
{
if (!fiSource.Exists) return null;
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);
int hresult2 = pssSetStorage.Open(ref guidSummaryProperties, (int)(STGM.DIRECT | STGM.SHARE_EXCLUSIVE), out psStorage);
pscSpecs[0].ulKind = 1;
pscSpecs[0].Name_Or_ID = new IntPtr((int)summaryPropertID);
hresult2 = psStorage.ReadMultiple(1, pscSpecs, pvValues);
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:
[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:
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?