internal State RefreshStorage(UnsafeNativeMethods.IPersistStorage iPersistStorage) { Debug.Assert(storage != null, "how can we not have a storage object?"); Debug.Assert(iLockBytes != null, "how can we have a storage w/o ILockBytes?"); if (storage == null || iLockBytes == null) return null; iPersistStorage.Save(storage, true); storage.Commit(0); iPersistStorage.HandsOffStorage(); try { buffer = null; ms = null; NativeMethods.STATSTG stat = new NativeMethods.STATSTG(); iLockBytes.Stat(stat, NativeMethods.Ole.STATFLAG_NONAME); length = (int) stat.cbSize; buffer = new byte[length]; IntPtr hglobal = UnsafeNativeMethods.GetHGlobalFromILockBytes(iLockBytes); IntPtr pointer = UnsafeNativeMethods.GlobalLock(new HandleRef(null, hglobal)); try { if (pointer != IntPtr.Zero) { Marshal.Copy(pointer, buffer, 0, length); } else { length = 0; buffer = null; } } finally { UnsafeNativeMethods.GlobalUnlock(new HandleRef(null, hglobal)); } } finally { iPersistStorage.SaveCompleted(storage); } return this; }