Does anyone know of any example code available to demonstrate how to use Structured Storage from within PB?
I am stuck as to how to define and use IEnumSTATSTG and STATSTG with EnumElements. I also would prefer not to have memory leaks caused by not destroying / releasing memory allocations/structures.
I have the following code:
Code: Select all
;
; Structured Storage Test
;
#STGM_DIRECT           = $00000000
#STGM_TRANSACTED       = $00010000
#STGM_SIMPLE           = $08000000
#STGM_READ             = $00000000
#STGM_WRITE            = $00000001
#STGM_READWRITE        = $00000002
#STGM_SHARE_DENY_NONE  = $00000040
#STGM_SHARE_DENY_READ  = $00000030
#STGM_SHARE_DENY_WRITE = $00000020
#STGM_SHARE_EXCLUSIVE  = $00000010
#STGM_PRIORITY         = $00040000
#STGM_DELETEONRELEASE  = $04000000
#STGM_CREATE           = $00001000
#STGM_CONVERT          = $00020000
#STGM_FAILIFTHERE      = $00000000
Procedure.l Ansi2Uni(ansi.s) 
  size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0) 
  Dim unicode.w(size) 
  MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size) 
  ProcedureReturn @unicode()  
EndProcedure 
  
Procedure.s Uni2Ansi(*Unicode.l) 
  size.l = WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, #Null, #Null, #Null, #Null) 
  ansi.s=Space(size) 
  WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, @ansi, size, #Null, #Null) 
  ProcedureReturn ansi  
EndProcedure 
  
; __ File path + name to a Structured Storage file...
sfile.s = "C:\\MyStore.sel"
; __ Make a UNICODE copy of the ANSI string...
*ptrFile=Ansi2Uni(sfile) 
; __ Initialise OLE...
OleInitialize_(0)
; __ Check to see if the file we are trying to use is really a Structured Storage file...
If (StgIsStorageFile_(*ptrFile) = #S_OK)
  *StorageFile.IStorage = 0
; __ Try to open the file...
  rs.l = StgOpenStorage_(*ptrFile, 0, #STGM_READ | #STGM_SHARE_EXCLUSIVE, 0, 0, @*StorageFile)
  If rs = #S_OK
; __ If we get here, then the file exists and it is the file we want...
    *enumStats.IEnumSTATSTG = 0
; __ NB:  STATSTG is not defined...this is a problem...
    elementSTATSTG.STATSTG
    
; __ If we could get here, then we prepare to enumerate the Storage / Stream elements...
    rs = EnumElements_(0, 0, 0, @*enumStats)
; __ This is where I am lost...    
    While (rs <> #S_FALSE)
    
    Wend
    
  EndIf
  
EndIf
; __ We have finished with OLE...let the system know...
OleUninitialize_()
If I can progress, then my aim is to build a library to assist in using Structured Storage, and I will gladly make the library and source code freely available upon completion. This would be my contribution to the PB community in return for your help and patience, and to Fred for building a neat programming language.
As you can see from my profile, I am a n00b, so please bear with me
Any comments / suggestions would be appreciated.
Best regards,
Techie42

