Skip to content

Commit

Permalink
Return accurate HRESULT for IPersistStorage Load/Save
Browse files Browse the repository at this point in the history
  • Loading branch information
lonitra committed Nov 2, 2022
1 parent 82f9cbe commit fa993d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ internal HRESULT IsDirty()
/// <summary>
/// Implements IPersistStorage::Load
/// </summary>
internal void Load(IStorage* stg)
internal HRESULT Load(IStorage* stg)
{
using ComScope<IStream> stream = new(null);
HRESULT hr = stg->OpenStream(
Expand All @@ -989,15 +989,20 @@ internal void Load(IStorage* stg)
{
// For backward compatibility: We were earlier using GetType().FullName
// as the stream name in v1. Lets see if a stream by that name exists.
stg->OpenStream(
hr = stg->OpenStream(
GetType().FullName!,
null,
STGM.STGM_READ | STGM.STGM_SHARE_EXCLUSIVE,
0,
stream);
}

Load(stream);
if (hr.Succeeded)
{
Load(stream);
}

return hr;
}

/// <summary>
Expand Down Expand Up @@ -1408,18 +1413,23 @@ internal unsafe HRESULT QuickActivate(Ole32.QACONTAINER pQaContainer, Ole32.QACO
/// <summary>
/// Implements IPersistStorage::Save
/// </summary>
internal void Save(IStorage* stg, BOOL fSameAsLoad)
internal HRESULT Save(IStorage* stg, BOOL fSameAsLoad)
{
using ComScope<IStream> stream = new(null);
stg->CreateStream(
HRESULT hr = stg->CreateStream(
GetStreamName(),
STGM.STGM_WRITE | STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE,
0,
0,
stream);
Debug.Assert(!stream.IsNull, "Stream should be non-null, or an exception should have been thrown.");
Debug.Assert(hr.Succeeded, "Stream should be non-null.");

if (hr.Succeeded)
{
Save(stream, fClearDirty: true);
}

Save(stream, fClearDirty: true);
return hr;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14113,9 +14113,9 @@ HRESULT IPersistStorage.Interface.Load(IStorage* pStg)

Debug.WriteLineIf(CompModSwitches.ActiveX.TraceInfo, "AxSource:IPersistStorage.Load");
Debug.Indent();
ActiveXInstance.Load(pStg);
HRESULT result = ActiveXInstance.Load(pStg);
Debug.Unindent();
return HRESULT.S_OK;
return result;
}

HRESULT IPersistStorage.Interface.Save(IStorage* pStgSave, BOOL fSameAsLoad)
Expand All @@ -14127,9 +14127,9 @@ HRESULT IPersistStorage.Interface.Save(IStorage* pStgSave, BOOL fSameAsLoad)

Debug.WriteLineIf(CompModSwitches.ActiveX.TraceInfo, "AxSource:IPersistStorage.Save");
Debug.Indent();
ActiveXInstance.Save(pStgSave, fSameAsLoad);
HRESULT result = ActiveXInstance.Save(pStgSave, fSameAsLoad);
Debug.Unindent();
return HRESULT.S_OK;
return result;
}

HRESULT IPersistStorage.Interface.SaveCompleted(IStorage* pStgNew)
Expand Down

0 comments on commit fa993d9

Please sign in to comment.