It is currently Wed Jan 27, 2021 5:36 am

All times are UTC + 1 hour

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Using Resource Dll created with Resource Hacker
PostPosted: Sat Jan 25, 2020 12:17 pm 

Joined: Wed Nov 06, 2019 10:28 am
Posts: 86

Because I don't like .ico, .gif, .png, ... stuff everywhere inside my program folder, I search how I could store those files inside one file.
Resource file bumped up and ... Resource Hacker !
I could easily add icons to a dll resource file with this soft and extract them with ExtractIcon_() WinApi.
The problem was with gif image which are stored as RCData.

Here is the code to use them : (you can use CatchImage() too instead of creating a file)

   (Value & $FFFF)

   Bool(Val & ~$FFFF)


Dim a_ImgResource(1) ; this array will stock the result of GetImagePointerFromResource()
                     ; a_ImgResource(0) = pointer to the image
                     ; a_ImgResource(1) = size of the image

; Load an image (gif, png, ...) from Dll Resource file created with Resource Hacker
; Depending on the destination of the image inside the Dll, Choose a known ResourceType like #RT_RCDATA or a custom one like "PNG"
; -- Parameters --
; a_ImgResource(1)         : Array containing pointer and size of the image in resource file
; DLL_Path                   : Path to the Dll Resource file
; Image_Name                : Name of the image inside the Dll (defined when you import the file with Resource Hacker)
; ResourceType             : Resource Type (
; CustomResourceTypeName    : Custom Name of the resource type (for example : if you import a png with Resource Hacker, it creates a "PNG" resource type)
; -- Return --
; 0 if error
; 1 if success and a_ImgResource() filled
Procedure.i GetImagePointerFromResource(Array a_ImgResource(1), DLL_Path.s, Image_Name.s, ResourceType = #RT_RCDATA, CustomResourceTypeName.s = "")

   Protected hModule ; dll module handle
   Protected hResource ; handle to the specified resource's information block
   Protected hData ; handle to the data associated with the resource
   Protected *pResource ; pointer to the first byte of the resource
   Protected SizeofResource ; number of bytes in the resource
   If hModule = #Null
      MessageRequester("Information", "LoadLibraryEx Error")
      ProcedureReturn 0
   If CustomResourceTypeName = ""
      hResource = FindResource_(hModule, Image_Name, MAKEINTRESOURCE(ResourceType))
      hResource = FindResource_(hModule, Image_Name, CustomResourceTypeName)
   If hResource = #Null
      MessageRequester("Information", "FindResource Error")
      ProcedureReturn 0
   hData = LoadResource_(hModule, hResource)
   If hData = #Null
      MessageRequester("Information", "LoadResource Error")
      ProcedureReturn 0
   *pResource = LockResource_(hData)
   If *pResource = #Null
      MessageRequester("Information", "LockResource Error")
      ProcedureReturn 0
   SizeofResource = SizeofResource_(hModule, hResource)
   a_ImgResource(0) = *pResource
   a_ImgResource(1) = SizeofResource
   ProcedureReturn 1

; Example :

; If GetImagePointerFromResource(a_ImgResource(), "resources.dll", "myGifName")
If GetImagePointerFromResource(a_ImgResource(), "resources.dll", "myPNGName", #RT_RCDATA, "PNG")
   ; If CreateFile(0,"test.gif")   
   If CreateFile(0,"test.png")
      WriteData(0, a_ImgResource(0), a_ImgResource(1))
      MessageRequester("Error", "Could not create file")

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: Majestic-12 [Bot] and 16 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