But I am not sure how to clear the memory for these strings.
LPOLESTR is not a BSTR and therefore the memory is not cleared with SysFreeString.
A CoTaskFreeMem on the array will not return an error. But this can not be true.
Update
Should be right about now.
LPOLESTR with COM-Objects are deleted with CoTaskFreeMem.
After description CoTaskFreeMem should not have a return value. But if it is zero, you can read the error with GetLastError.
Code: Select all
;- EnumString Helper
Procedure EnumStringToArray(*EnumString.IEnumString, Array Result.s(1), AutoRelease = #True) ; Result Count
Protected r1, cnt, size, index, offset
size = 100
Dim pString.i(size)
offset = 0
*EnumString\Reset()
Repeat
r1 = *EnumString\Next(size, @pString(), @cnt)
If r1 <> #S_OK And r1 <> #S_FALSE
Debug FormatMessage(r1)
ProcedureReturn 0
EndIf
If cnt > 0
ReDim Result(offset + cnt - 1)
For index = 0 To cnt - 1
Result(offset + index) = PeekS(pString(index))
If CoTaskMemFree_(pString(index)) = 0
Debug "EnumString Error: " + FormatMessage(GetLastError_())
EndIf
Next
offset + cnt
EndIf
Until cnt = 0
If AutoRelease
*EnumString\Release()
EndIf
ProcedureReturn ArraySize(Result()) + 1
EndProcedure