Jump to content

Resources UDF


Zedna
 Share

Recommended Posts

have fun so :)

i've been two days on this and no way

i wonder if i have to use EnumResourceTypes before, to find the correct Icon Index after. Dunno.

I Know that AutoIt uses this with guictrlsetimage, that's why it supports icon from exe.

the pptico.exe is installed with office 2000. You have wordico.exe for Word, xlicons.exe for Excel, and so on....

i can't attach the xe (proxy issue in my firm) but you can try this with any exe i think.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

ok i've found the problem ...

the problem seems that you have to use loadlibrary and not getmodulehandle for Exe.

i send a new version of your resource get if you permit this ... when it will work correctly

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

ok i've found the problem ...

the problem seems that you have to use loadlibrary and not getmodulehandle for Exe.

i send a new version of your resource get if you permit this ... when it will work correctly

I know about that.

In your previously posted code was LoadLibrary and GetModuleHandle was changed too so I didn't expected problem in this.

But my UDF is intended only for using with AutoIt own EXE file as mentioned in notes in my first post.

Link to comment
Share on other sites

But my UDF is intended only for using with AutoIt own EXE file as mentioned in notes in my first post.

i read this but i've forgotten. :) , sorry about that

there was a mistaker in my previous post because i don't use the handle from loadlibrary but from getmodulehandle. Here was the mistake.

for now i have to understand now the RT_GROUP_ICON.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

ok here it is :

Func _ResourceGet($ResName, $ResType = 10, $ResLang = 0, $Res_Exe = "") ; $RT_RCDATA = 10
    Local Const $IMAGE_BITMAP = 0
    Local $hInstance, $hBitmap, $InfoBlock, $GlobalMemoryBlock, $MemoryPointer, $ResSize
    If $Res_Exe = "" Then
        ConsoleWrite("Toto" & @crlf)
        $hInstance = DllCall("kernel32.dll", "int", "GetModuleHandleA", "int", $Res_Exe)
        $hInstance = $hInstance[0]
    Else
        ConsoleWrite("Exe " & @CRLF)
        ; Load the DLL/EXE without executing its code
        $hInstance = _API_LoadLibraryEX ($Res_Exe,$LOAD_LIBRARY_AS_DATAFILE)
    EndIf
    If $ResType = $RT_BITMAP Then
        $hBitmap = DllCall("user32.dll", "hwnd", "LoadImage", "hwnd", $hInstance, "str", $ResName, _
                "int", $IMAGE_BITMAP, "int", 0, "int", 0, "int", 0)
        If @error Then Return SetError(1, 0, 0)
        $hBitmap = $hBitmap[0]
        Return $hBitmap ; returns handle to Bitmap
    EndIf
    If $ResLang <> 0 Then
        $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceExA", "int", $hInstance, "str", $ResName, "long", $ResType, "short", $ResLang)
    Else
        $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceA", "int", $hInstance, "str", $ResName, "long", $ResType)
    EndIf
    If @error Then Return SetError(2, 0, 0)
    $InfoBlock = $InfoBlock[0]
    If $InfoBlock = 0 Then Return SetError(3, 0, 0)
    $ResSize = DllCall("kernel32.dll", "dword", "SizeofResource", "int", $hInstance, "int", $InfoBlock)
    If @error Then Return SetError(4, 0, 0)
    $ResSize = $ResSize[0]
    If $ResSize = 0 Then Return SetError(5, 0, 0)
    $GlobalMemoryBlock = DllCall("kernel32.dll", "int", "LoadResource", "int", $hInstance, "int", $InfoBlock)
    If @error Then Return SetError(6, 0, 0)
    $GlobalMemoryBlock = $GlobalMemoryBlock[0]
    If $GlobalMemoryBlock = 0 Then Return SetError(7, 0, 0)
    $MemoryPointer = DllCall("kernel32.dll", "int", "LockResource", "int", $GlobalMemoryBlock)
    If @error Then Return SetError(8, 0, 0)
    $MemoryPointer = $MemoryPointer[0]
    If $MemoryPointer = 0 Then Return SetError(9, 0, 0)
    SetExtended($ResSize)
    Return $MemoryPointer
EndFunc   ;==>_ResourceGetoÝ÷ Úz0¶¬jjeyÊz'hm©Úëh­ëkëÞ¶®¶²¡û-®ç-º·yÆ®±è¡j÷§¡Énzá£hÒÊjx^áz«¦Ëh­ëkëÞ¶¢vÞiÈbrìríj)Þv)íäS

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

I've been trying to get this to work, and I'm guessing I've missed something basic. Anyone spot my mistake?

Here is what I have:

#AutoIt3Wrapper_Res_File_Add=.\Images\Button.bmp, bitmap, button_bmp       ; I have verified this is adding the resource

; this is old code that works with the files external of the EXE
;$Button_Std = GUICtrlCreateButton ("", 119, 588, 179, 25,$BS_BITMAP)
;GUICtrlSetImage (-1, ".\Images\Button.bmp")

; This is trying to use this UDF to do the same, but with internal EXE resource
$Button_Std = GUICtrlCreateButton ("", 119, 588, 179, 25,$BS_BITMAP)
$hBmp = _ResourceGet("button_bmp", $RT_BITMAP)
GUICtrlSetImage (-1, $hBmp)

So, anything just jump out at you?

Link to comment
Share on other sites

I've been trying to get this to work, and I'm guessing I've missed something basic. Anyone spot my mistake?

Here is what I have:

#AutoIt3Wrapper_Res_File_Add=.\Images\Button.bmp, bitmap, button_bmp      ; I have verified this is adding the resource

; this is old code that works with the files external of the EXE
;$Button_Std = GUICtrlCreateButton ("", 119, 588, 179, 25,$BS_BITMAP)
;GUICtrlSetImage (-1, ".\Images\Button.bmp")

; This is trying to use this UDF to do the same, but with internal EXE resource
$Button_Std = GUICtrlCreateButton ("", 119, 588, 179, 25,$BS_BITMAP)
$hBmp = _ResourceGet("button_bmp", $RT_BITMAP)
GUICtrlSetImage (-1, $hBmp)

So, anything just jump out at you?

Read carefully my first post

Notes:

* _ResourceSetImageToCtrl() tested only on picture control (probably don't support buttons,labels for now)

Link to comment
Share on other sites

@Zedna

Running your include resource.au3 with Opt('MustDeclareVars', 1) I think I have discovered a small bug.

In function _ResourceGetAsString the variable $struct is not initialized thus getting global.

I have changed

$struct = DllStructCreate("char[" & $ResSize & "]", $ResPointer)oÝ÷ ÚÚºÚ"µÍØØ[    ÌÍÜÝXÝHÝXÝÜX]J  ][ÝØÚÉ][ÝÈ    [È ÌÍÔÔÚ^H    [È ][Ý×I][ÝË   ÌÍÔÔÚ[
Edited by MCP
Link to comment
Share on other sites

@Zedna

Running your include resource.au3 with Opt('MustDeclareVars', 1) I think I have discovered a small bug.

In function _ResourceGetAsString the variable $struct is not initialized thus getting global.

I never used Opt('MustDeclareVars', 1) so such kind or bugs (not affecting functionality) may be in more my scripts.

Anyway thanks for pointing to this bug.

I will fix it in the next version of my UDF.

Link to comment
Share on other sites

Updated first post:

2007-10-16

- added _ResourcePlaySound() - thanks Larry

- corrected local declaration of $struxt - was problem when Opt("MustDeclareVars",1)

- updated resource_test.au3 and resource.au3 in resource_au3.zip

EDIT:

Here is post from Larry where I got _ResourcePlaySound() code from

Edited by Zedna
Link to comment
Share on other sites

In function _ResourceGetAsString the variable $struct is not initialized thus getting global.

I am fairly sure that setting a variable which has not been declared already to some value inside a function does not give it global scope.

Here is a small test

$c = whatisit()

If IsDeclared("g") Then MsgBox(0,'val of $g is ',Eval("g"))

Func whatisit()
    $g = 99
    Return $g
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I am fairly sure that setting a variable which has not been declared already to some value inside a function does not give it global scope.

Here is a small test

$c = whatisit()
   
   If IsDeclared("g") Then MsgBox(0,'val of $g is ',Eval("g"))
   
   Func whatisit()
       $g = 99
       Return $g
   EndFunc
Thanks for underlining it (I haven't tested it, but I do believe you, of course). Anyway, declaring variables as local helps us - the coders - not to confuse us. The compiler may easily check the variables scopes, but we are not as good as it and we always have to assume they are globals if they have not been declared.

Your sample code points out the compiler implementation details, but does not change the need for clarity and for omitting any possible interference with other libraries variables either with our latest project variables.

From my own experience, I believe that globals should be avoided as much as possible, but - when needed, and in many situations we need to declare and use them - it should be always good practice to declare and later discover them at the beginning of the source.

In such a great library they are simply a need to let every function integrate well, silently, with no issue, but their added functionality.

That is why it is important in this case: you (we) will never have unwanted collisions, with no regard to the coding style that can be completely different and preserved.

Link to comment
Share on other sites

  • 1 month later...

;) Wooooohooo suuuper, i found what im looking for !!! Now we can add all resources in 1 exe file !!! THATs cool !!! now my programs, cracks, remote control tools will be better :P) BIG THX !!!

only 2 questions:

> can I extract those resources automaticly by autoit ?

> can I add other executables in resources and then something like unpack them ?

spasibki

Edited by Enforcer
[RU] Zone
Link to comment
Share on other sites

:) Wooooohooo suuuper, i found what im looking for !!! Now we can add all resources in 1 exe file !!! THATs cool !!! now my programs, cracks, remote control tools will be better ;) ) BIG THX !!!

only 2 questions:

> can I extract those resources automaticly by autoit ?

> can I add other executables in resources and then something like unpack them ?

spasibki

I'm happy that you are happy :P

Read carefully ALL my first post.

- there are still some limitations: for example supports only BMP (not JPG,GIF,PNG)

- there are examples what can be done (extraction/use in AutoIt)

Edited by Zedna
Link to comment
Share on other sites

  • 2 weeks later...

resource_test.au3

What should i see hire? all i see is blank Gui, is this the way it should be?

so i dont get it now, this thing writes 1.bmp into my script.exe & when i double click my script.exe then it does not extract that 1.bmp from the exe, but instead reads the 1.bmp from the exe & can display it on the gui?

or when i run this nothing happens:

#AutoIt3Wrapper_Res_File_Add=image1.bmp, bitmap, TEST_BMP_1 ; Filename,Section,ResName
#include "resources.au3"
 
; save binary data from resource to file
_ResourceSaveToFile(@ScriptDir & "\binary_data.dat", "TEST_BIN_1")
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

resource_test.au3

What should i see hire? all i see is blank Gui, is this the way it should be?

so i dont get it now, this thing writes 1.bmp into my script.exe & when i double click my script.exe then it does not extract that 1.bmp from the exe, but instead reads the 1.bmp from the exe & can display it on the gui?

or when i run this nothing happens:

#AutoIt3Wrapper_Res_File_Add=image1.bmp, bitmap, TEST_BMP_1 ; Filename,Section,ResName
#include "resources.au3"
 
; save binary data from resource to file
_ResourceSaveToFile(@ScriptDir & "\binary_data.dat", "TEST_BIN_1")
You must run all examples only in compiled form (compiled EXE file) and no directly by Run from Scite.

I think it's your case.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...