Re:Strings and the CLR – A Special Relationship
by asveikau on Wednesday June 01, 2016 @10:16AM
(#11814499)
I would think, especially for out parameters and return values, you would need to copy to interop with BSTRs because they are supposed to live on the COM heap (SysAllocString) and CLR wouldn't use that by default.
Re:Strings and the CLR – A Special Relationship
by matthewwarren on Wednesday June 01, 2016 @04:52AM
(#11812950)
I love comments like that, it's almost a history lesson on VB and the CLR!
Re:Strings and the CLR – A Special Relationship
by adzm on Wednesday June 01, 2016 @02:43PM
(#11817042)
Then you'd probably love to know why the OLE DATE epoch is 1899-12-30...
also the B in BSTR is for Basic!
https://blogs.msdn.microsoft.com/ericlippert/2003/09/16/eric...
It looks like if you use the automatic BSTR marshaler it creates a copy[1], though the CLR is so big it's hard for me to say that with confidence. Taking the address of a string with the fixed statement in C# of course won't allocate and that pointer can be passed to APIs that expected Unicode strings.
[0]: https://github.com/dotnet/coreclr/blob/a123c3972c447c8bcfa18... [1]: https://github.com/dotnet/coreclr/blob/a123c3972c447c8bcfa18...