问题描述
难道仅仅字节合并为en code中的数据?
Is it just the way the bytes are combined to "encode" the data?
我很好奇,因为我不知道有一个RCW自动拍摄.NET字符串,并将其转换成一个COM BSTR。我猜它只是形成从.NET字符串转化的有效COM BSTR。
I'm curious because I wonder how an RCW automatically takes a .NET string and transforms it into a COM BSTR. I'm guessing it just forms a valid COM BSTR transformed from the .NET string.
相关阅读:我可以构建自己的有效BSTR在.NET中使用一个字节型
Related: Could I construct my own valid BSTR using a byte type in .NET?
推荐答案
这两个字符串类型不是在所有有关。一个转换已经发生一种类型转换为另一种。
The two string types are not related at all. A transformation has to occur to convert one type to another.
一个BSTR有一些必须遵循包括通过SysAllocString *,释放与SysFreeString分配的约定,其长度preFIX,和两个空字符终止。
A BSTR has a number of conventions that must be followed in including allocated via SysAllocString*, deallocated with SysFreeString, having a length prefix, and a terminator of two null characters.
http://msdn.microsoft.com/en-us/library/ms221069.aspx
一个.NET字符串是通过托管堆中分配的托管类型。它的寿命是由CLR垃圾收集管理。
A .Net string is a managed type that is allocated via the managed heap. It's lifetime is managed by the CLR garbage collector.
要构建自己的BSTR,这将是更好的使用Marshal.StringToBSTR:
To construct your own BSTR, it would be much better to use Marshal.StringToBSTR:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.stringtobstr.aspx
如果这还不够好,你可以的PInvoke SysAllocString:
If that's not good enough you can pinvoke SysAllocString:
http://msdn.microsoft.com/en-us/library/ms221458.aspx
这篇关于一个COM字符串(BSTR)和.NET字符串之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!