Felix Dombek
Felix Dombek

Reputation: 14372

In VB6, do I need to call SysFreeString on strings allocated with SysAllocString?

I have a VB6 app which uses a C++ COM DLL and BSTRs are passed between the two. I return BSTRs from the C++ DLL with return ::SysAllocString(L"example");.

Do I need to call SysFreeString on such a string in the following example?

Sub Main()
    Dim own_str As String
    Dim dll_str As String

    own_str = "my own string"
    dll_str = DllComObj.FunctionReturningString()
    ' when leaving the scope:
    ' no need to free own_str,
    ' do I need to free dll_str?
End Sub

Upvotes: 1

Views: 582

Answers (1)

GSerg
GSerg

Reputation: 78185

No you don't. VB6 will free them as BSTR is its native string format.

Upvotes: 3

Related Questions