You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generally when working with COM in C++, there is very good guidance on what you need to do to clean up after yourself, depending on whether you are dealing with smart pointers or not. Take for example the following snippet from MS documentation:
Is there guidance on how to clean up COM references such as these, when using the crate? Do we just drop(pObj)? Or does the crate implement some type of smart pointers that are automatically cleaned up when they go out of scope? Looking at the documentation, it doesn't really imply I need to do any cleanup.
SImilarly, coming from C++, you are used to SysAllocString/SysFreeString to work with BSTR (unless you are using smart pointers), can I assume the rust implementation is a smart pointer, since there is no specific cleanup documented?
The text was updated successfully, but these errors were encountered:
vpopescu
changed the title
Guidance on working with COM
Cleanup guidance on working with COM
Oct 27, 2022
vpopescu
changed the title
Cleanup guidance on working with COM
Cleanup guidance when working with COM
Oct 27, 2022
COM interface implementations in the windows crate provide automatic resource management. While not immediately apparent from the documentation they transparently wrap an IUnknown struct, which has the Drop (and Clone) traits implemented, dealing with reference counting and releasing resources as needed.
Likewise, the BSTR struct provides both Drop and Clone implementations, so resource management is supplied out-of-the-box here as well.
This crate also has a large set of samples, such as com_uri and wmi, that illustrate proper use of the crate. The latter is also insightful in acknowledging that VARIANTs have not yet received resource management support.
Thank you, very useful information, it may be good to add it to the FAQ discussed in another issue, if that will still happen (or maybe it's not a "frequently" asked question. I think SAFEARRAY may be in the same category as VARIANT, requiring SafeArrayDestroy()?
I hope this doesn't sound too generic.
Generally when working with COM in C++, there is very good guidance on what you need to do to clean up after yourself, depending on whether you are dealing with smart pointers or not. Take for example the following snippet from MS documentation:
Is there guidance on how to clean up COM references such as these, when using the crate? Do we just drop(pObj)? Or does the crate implement some type of smart pointers that are automatically cleaned up when they go out of scope? Looking at the documentation, it doesn't really imply I need to do any cleanup.
SImilarly, coming from C++, you are used to SysAllocString/SysFreeString to work with BSTR (unless you are using smart pointers), can I assume the rust implementation is a smart pointer, since there is no specific cleanup documented?
The text was updated successfully, but these errors were encountered: