Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Resources UDF


  • Please log in to reply
625 replies to this topic

#61 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 581 posts

Posted 05 October 2007 - 07:44 AM

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 :

  • Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here







#62 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 581 posts

Posted 05 October 2007 - 02:07 PM

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 :

  • Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here

#63 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,710 posts

Posted 05 October 2007 - 02:17 PM

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.

#64 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 581 posts

Posted 05 October 2007 - 02:27 PM

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 :

  • Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here

#65 arcker

arcker

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 581 posts

Posted 05 October 2007 - 05:04 PM

ok here it is :

AutoIt         
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   ;==>_ResourceGetƒo݊÷ Úz0¶¬jjeyÊz'hŸm™©Úë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 :

  • Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here

#66 Jazkal

Jazkal

    Wayfarer

  • Active Members
  • Pip
  • 82 posts

Posted 09 October 2007 - 12:44 PM

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?

#67 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,710 posts

Posted 09 October 2007 - 04:05 PM

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)



#68 Jazkal

Jazkal

    Wayfarer

  • Active Members
  • Pip
  • 82 posts

Posted 09 October 2007 - 05:32 PM

Sorry about that, missed that one.

Thanks for the good work.

#69 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,710 posts

Posted 09 October 2007 - 09:09 PM

Sorry about that, missed that one.

Thanks for the good work.


No problem.
Look here for inspiration what can be possible future evolution with GDI+

#70 MCP

MCP

    Adventurer

  • Active Members
  • PipPip
  • 107 posts

Posted 11 October 2007 - 08:01 AM

@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, 11 October 2007 - 08:02 AM.


#71 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,710 posts

Posted 11 October 2007 - 04:05 PM

@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.

#72 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,710 posts

Posted 16 October 2007 - 10:09 PM

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, 16 October 2007 - 10:39 PM.


#73 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,313 posts

Posted 16 October 2007 - 10:52 PM

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.

#74 MCP

MCP

    Adventurer

  • Active Members
  • PipPip
  • 107 posts

Posted 21 October 2007 - 08:19 PM

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.

#75 Enforcer

Enforcer

    Prodigy

  • Active Members
  • PipPipPip
  • 150 posts

Posted 28 November 2007 - 01:59 PM

;) 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, 28 November 2007 - 02:11 PM.

[RU] Zone

#76 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,710 posts

Posted 28 November 2007 - 02:45 PM

:) 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, 28 November 2007 - 02:46 PM.


#77 goldenix

goldenix

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 738 posts

Posted 12 December 2007 - 01:44 PM

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, 12 December 2007 - 01:55 PM.


#78 LarryDalooza

LarryDalooza

    Schmember

  • Active Members
  • PipPipPipPipPipPip
  • 955 posts

Posted 12 December 2007 - 02:47 PM

TEST_BMP_1

TEST_BIN_1

for starters...
Posted ImageAutoIt3 Yahoo Group - Expert LarryA tool of Big Blue...

#79 LarryDalooza

LarryDalooza

    Schmember

  • Active Members
  • PipPipPipPipPipPip
  • 955 posts

Posted 12 December 2007 - 03:54 PM

Please no PM... post in help forum...

Lar.
Posted ImageAutoIt3 Yahoo Group - Expert LarryA tool of Big Blue...

#80 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,710 posts

Posted 12 December 2007 - 04:14 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users