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

No support to marshal Strings in structures to and from wchar_t. #40718

Closed
sfoslund opened this issue Aug 12, 2020 · 4 comments
Closed

No support to marshal Strings in structures to and from wchar_t. #40718

sfoslund opened this issue Aug 12, 2020 · 4 comments

Comments

@sfoslund
Copy link
Member


Issue moved from dotnet/sdk#12809


From @johndaintree on Thursday, August 6, 2020 2:28:49 PM

I have a similar issue to the (now close, but not fixed) one made here:

#8271 (comment)

In that I have a lot of unmanaged code that uses structures that contain pointers to arrays of wchar_t. I'd like to be able to marshal these structures in an out of managed code as Strings.

However, there is no UnmanagedType field that will do this. There is UnmanagedTtype.LPWStr, which will work for Windows (2 byte wchar_t), but no equivalent for the Unixes (which have a 4 byte wchar_t). The only portable option is to use UnmanagedType.LPUTF8Str but then I'll have to change all my unmanaged code (in multiple places) to cope.

Custom marshalling also doesn't work on fields in structures- otherwise I'd use that. I guess I could refactor all the code into functions with a parameter per field in the structure - I believe that custom marshalling will work there. But it seems like a lot hoops to jump though where ( I reckon) the built in marshaller could do it.

@sfoslund
Copy link
Member Author


Issue moved from dotnet/sdk#12809


From @johndaintree on Thursday, August 6, 2020 2:31:35 PM

It would also be great of System.Runtime.InteropServices.Charset could be similarly extended for use with P/Invoke.

@elinor-fung
Copy link
Member

cc @jkoritzinsky This looks like a (potentially common) use case that would be enabled with the new struct marshalling design / attributes.

@elinor-fung elinor-fung removed the untriaged New issue has not been triaged by the area owner label Aug 14, 2020
@elinor-fung elinor-fung added this to the 6.0.0 milestone Aug 14, 2020
@jkoritzinsky
Copy link
Member

Yes, the new struct marshalling code-gen should cover this scenario pretty well.

@AaronRobinsonMSFT
Copy link
Member

We've no plans to update our built-in marshallers to support this. It is however something we will be taking into account with out DllImport source generator – see #43060.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants