Resource
Posted: Fri Nov 25, 2005 11:43 pm
				
				Code updated For 5.20+
With this functions you can include files, and use it with purebasic functions like CatchImage / CatchSound or extract included file .
Create a file with RC extension and include it as RC_DATA Resource type
Path can be absolute or relative
Exemple :
			With this functions you can include files, and use it with purebasic functions like CatchImage / CatchSound or extract included file .
Create a file with RC extension and include it as RC_DATA Resource type
Path can be absolute or relative
Exemple :
REG RCData "C:\WINDOWS\REGEDIT.EXE"
SON RCData "son.wav"
IMAGE RCData "image.bmp"
Code: Select all
;/ SaveResourceAs(Name.s,File.s) Save the resource as a file
;/ GetResourcePointer(Name.s) is usefull with PureBasic CatchXXX functions (CatchImage / CatchSound ... )
ProcedureDLL SaveResourceAs(Name.s,File.s)
  
  ; (Use GetModuleHandle_ if you want to specify another file)
  
  HandleResource= FindResource_(0,@Name,#RT_RCDATA)
  If HandleResource
    HandleGlobalMemoryBlock=LoadResource_(0,HandleResource)
    PointerFirstByteOfTheResource=LockResource_(HandleGlobalMemoryBlock)
    
    ; Get size of the resource
    Size= SizeofResource_(Handle,HandleResource)
    
    ; Save the file
    FileId=OpenFile(#PB_Any,File)
    If FileId
      WriteData(FileId,HandleGlobalMemoryBlock,Size)
      CloseFile(FileId)
    EndIf
    
    ; Test if the file is written
    If FileSize(File)=Size
      ProcedureReturn 1
    EndIf
  EndIf
  
EndProcedure
ProcedureDLL GetResourcePointer(Name.s)
  
  ; (Use GetModuleHandle_ if you want to specify another file)
  
  HandleResource= FindResource_(0,@Name,#RT_RCDATA)
  If HandleResource
    HandleGlobalMemoryBlock=LoadResource_(0,HandleResource)
    PointerFirstByteOfTheResource=LockResource_(HandleGlobalMemoryBlock)
    
    ProcedureReturn HandleGlobalMemoryBlock
  EndIf
EndProcedure
ProcedureDLL GetResourceSize(Name.s)
  
  ; (Use GetModuleHandle_ if you want to specify another file)
  
  HandleResource= FindResource_(0,@Name,#RT_RCDATA)
  If HandleResource
    HandleGlobalMemoryBlock=LoadResource_(0,HandleResource)
    PointerFirstByteOfTheResource=LockResource_(HandleGlobalMemoryBlock)
    
    ; Return the size of the resource
    Size= SizeofResource_(Handle,HandleResource)
    ProcedureReturn Size
  EndIf
  
EndProcedure