windows-rs icon indicating copy to clipboard operation
windows-rs copied to clipboard

Additional string types for CoTaskMemAlloc'ed strings & others

Open talagrand opened this issue 4 months ago • 1 comments

Suggestion

With recent improvements to windows-rs we've been able to get rid of most of our bespoke RAII helpers, but we still have 2 which could be of general interest to others:

  • An owned string type for interacting with strings from APIs that use CoTaskMemoAlloc'ed strings
  • An owned string type for UNICODE_STRINGs. This could be satisfied if there was a specialization of Owned for this struct, though of course an actual string struct would have benefits like conventional string methods.

The first especially is all over COM, and given that underlying C data type is just PWSTR it would be great to have representation in the type system. The ideal case is of course to have method signatures directly interact with string types matching the allocation strategy, but if this is not possible due to missing API metadata, just having a standardized helper that could immediately take string ownership would be a great first step.

talagrand avatar Nov 08 '25 19:11 talagrand

This is currently a little challenging because the Win32 metadata doesn't do a great job of articulating these semantics reliably and consistently. I think that once we have more canonical metadata we'll be able to rethink how we do this.

kennykerr avatar Nov 12 '25 19:11 kennykerr