Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComStream indicate that inner IStream is not readable/writeable incorrectly #504

Closed
zhuxb711 opened this issue Jan 16, 2025 · 4 comments
Closed

Comments

@zhuxb711
Copy link
Contributor

zhuxb711 commented Jan 16, 2025

Construct the ComStream with this constructor

/// <summary>Initializes a new instance of the ComStream class.</summary>
/// <param name="stream">A ComTypes.IStream</param>
public ComStream(IStream stream) => comStream = stream;

However, CanSeek/CanRead/CanWrite are all false (Only consider netStream)

/// <summary>Gets a value indicating whether this instance can read.</summary>
/// <value><see langword="true"/> if this instance can read; otherwise, <see langword="false"/>.</value>
public override bool CanRead => netStream?.CanRead ?? false;
/// <summary>Gets a value indicating whether this instance can seek.</summary>
/// <value><see langword="true"/> if this instance can seek; otherwise, <see langword="false"/>.</value>
public override bool CanSeek => netStream?.CanSeek ?? false;
/// <summary>Gets a value indicating whether this instance can timeout.</summary>
/// <value><see langword="true"/> if this instance can timeout; otherwise, <see langword="false"/>.</value>
public override bool CanTimeout => netStream?.CanTimeout ?? false;
/// <summary>Gets a value indicating whether this instance can write.</summary>
/// <value><see langword="true"/> if this instance can write; otherwise, <see langword="false"/>.</value>
public override bool CanWrite => netStream?.CanWrite ?? false;

Should use IStream.Stat(out STATSTG pstatstg, int grfStatFlag) to get STATSTG.grfMode and check whether the stream is readable/writeable instead of simply return false.

For IStream, I think CanSeek should always true & CanTimeout should always false

// grfMode reference
STGM_READ // readonly
STGM_WRITE // writeonly
STGM_READWRITE // read/write
@dahall
Copy link
Owner

dahall commented Jan 21, 2025

Given:

STGM_READ = 0x00000000,
STGM_WRITE = 0x00000001,
STGM_READWRITE = 0x00000002,

I think the following is correct given different values of STATSTG:

public override bool CanRead => (GetStats().grfMode & 0x00000003) is 0 or 2;
public override bool CanSeek => netStream?.CanSeek ?? true;
public override bool CanTimeout => netStream?.CanTimeout ?? false;
public override bool CanWrite => (GetStats().grfMode & 0x00000003) is 1 or 2;

Do you agree?

dahall pushed a commit that referenced this issue Jan 21, 2025
@zhuxb711
Copy link
Contributor Author

I would prefer use IsFlagSet to check the flags

public static bool IsFlagSet<T>(this T flags, T flag) where T : struct, Enum

Anyway, it looks good. Thanks~

@zhuxb711
Copy link
Contributor Author

By the way, would you release the next version in the near future?

@dahall
Copy link
Owner

dahall commented Jan 21, 2025

Yes, I plan to push 4.0.5 by the end of the month.

@dahall dahall closed this as completed Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants