It is currently Wed Oct 28, 2020 6:30 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: EnumString Helper (COM Objects)
PostPosted: Fri Jul 24, 2020 3:24 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2683
Location: Germany
With the query of the EnumString\Next you pass an array which can be entered with the pointer to the strings LPOLESTR.
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:
;- 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

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 94 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye