开发者

P/Invoke BSTR from unmanaged code

开发者 https://www.devze.com 2023-03-07 12:24 出处:网络
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 h

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消