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

Additional hint for the summary of IPortableDeviceContent::CreateObjectWithPropertiesAndData #483

Closed
NilsHoyer opened this issue Sep 2, 2024 · 8 comments

Comments

@NilsHoyer
Copy link

In your description of IPortableDeviceContent::CreateObjectWithPropertiesAndData I would like to have a hint, that the stream must be released and how I should do that.

https://learn.microsoft.com/en-us/windows/win32/api/portabledeviceapi/nf-portabledeviceapi-iportabledevicecontent-createobjectwithpropertiesanddata

Same for IPortableDeviceResources::GetStream:
https://learn.microsoft.com/en-us/windows/win32/api/portabledeviceapi/nf-portabledeviceapi-iportabledeviceresources-getstream

PS I use a Marshal method for releasing and that works fine for me. But I mention this after I spend 30 to find this out (call me "stupid" if you want 🤫).

@dahall
Copy link
Owner

dahall commented Sep 4, 2024

For both methods, the XML comments exactly match those in the links you provided. Was there more you think is needed?

@NilsHoyer
Copy link
Author

I didn't find this text in VS 2022:

The SDK allocates this memory, and the caller must release it using CoTaskMemFree.

@dahall
Copy link
Owner

dahall commented Sep 6, 2024

Right. The .NET framework, when marshaling strings, will internally call CoTaskMemFree on them before returning the string.

The IStream parameter does have the correct text for what needs to be done.

The caller must release this interface when it is done with it.

@dahall dahall closed this as completed Sep 6, 2024
@NilsHoyer
Copy link
Author

I'm using Marshal.ReleaseComObject(stream):
https://learn.microsoft.com/de-de/dotnet/api/system.runtime.interopservices.marshal.releasecomobject?view=net-8.0

If I don't call it, I can't use both mentioned methods again. While trying it, I get a message, that a resource is busy. (Sorry, at this moment I can't provide the correct error code or message.)

@dahall
Copy link
Owner

dahall commented Sep 9, 2024

Good. You're doing exactly what the documentation requires, but in .NET fashion.

@NilsHoyer
Copy link
Author

... and I believe, this hint inside your description would be helpful for other people. Because of this, I opened this issue.

@dahall
Copy link
Owner

dahall commented Sep 10, 2024

Added that note to those methods.

@NilsHoyer
Copy link
Author

Your changes are exactly, what I hope other developer helps. Thank you!

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