Passing a string from C # to cpp using COM

I have a C # COM server that is consumed by the cpp client.

One of the C # methods returns a string.

In cpp, the returned string is represented in Unicode (UTF-16), at least according to the kind of memory.

  • Is this always the case with COM strings?
  • Is there a way to use UTF-8 instead?
  • I saw some code where strings were passed between cpp and C # as arrays of bytes. Is there any use in this?
+3
source share
2 answers
  • Yes. The standard COM string type is BSTR. This is a Unicode string encoded in UTF16, just like the native Windows string type.
  • , COM- UTF8, . UTF8 , , . Unicode UTF8 1 4 . , .
  • C ++ 8- , char. , . , 8- . , , , , , 8- . , 1000 . .
+1
  • .
  • . [return: MarshalAs(UnmanagedType.LPStr)] #, ANSI Unicode.
  • , , , , , , .
0

Source: https://habr.com/ru/post/1742595/


All Articles