P/Invoke BSTR from unmanaged code
What should be the VB signature for the unmanaged function void PopulateBSTR(BSTR outstring)?
The function PopulateBSTR does a SysAllocString and populates the string. Note the unmanagaed signature has the argument BSTR and not BSTR*. I can marshal the BSTR string using IntPtr signature when the C++ signature has BSTR* as the argument.
(The unmanaged code is an external dll which I cannot modify but开发者_StackOverflow I need to use.)
Looking at PInvoke.net, it looks like you need to use the MarshallAs Attribute to indicate that it should be treated as a BSTR
.
Need to specify CharSet = CharSet.Unicode
in the attribute list of dllimport
. Catch it as a StringBuilder
rather than a string class.
精彩评论