开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜