Jump to content

Resources UDF


Zedna
 Share

Recommended Posts

  • Moderators

Zedna,

I have found a small problem when using your UDF.

The function _ResourceGetAsBytes did not get the resource as bytes. At least not until I changed the final lines to read:

$struct = DllStructCreate("byte[" & $ResSize & "]", $ResPointer)
Return DllStructGetData($struct, 1); returns struct with bytes

Rather than the original:

Return DllStructCreate("byte[" & $ResSize & "]", $ResPointer); returns struct with bytes

When I found that the AsBytes function did not work, I tried copying the code from the _ResourceGetAsString function above, which I had already used and knew worked well.

It might well be Vista (I am running x32 Home Premium), or more probably my understanding of the UDF. The code I am using to get the resource in and out is as follows:

#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, M:\Program\Au3 Scripts\Test\162.bin, rcdata, BIN_162, 0
...
...
; Load the 162 data from the saved resource
$data = _ResourceGetAsBytes("BIN_162")

Thanks for producing the UDF. I do hope it is an easy fix - like pointing out my error and smacking me over the head!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello, I was simply wondering if there was a way to run an executable this way.

So instead of using file install simple use this method to include an executable(or its binary data as a string) and then run the application without ever writing it to a file.

I was just wondering if it was possible. And if so, hwo would one go about doing so.

Thanks

Link to comment
Share on other sites

Hello, I was simply wondering if there was a way to run an executable this way.

So instead of using file install simple use this method to include an executable(or its binary data as a string) and then run the application without ever writing it to a file.

I was just wondering if it was possible. And if so, hwo would one go about doing so.

Thanks

NO. It's not possible.

Link to comment
Share on other sites

Zedna,

I have found a small problem when using your UDF.

The function _ResourceGetAsBytes did not get the resource as bytes. At least not until I changed the final lines to read:

$struct = DllStructCreate("byte[" & $ResSize & "]", $ResPointer)
Return DllStructGetData($struct, 1); returns struct with bytes

Rather than the original:

Return DllStructCreate("byte[" & $ResSize & "]", $ResPointer); returns struct with bytes

When I found that the AsBytes function did not work, I tried copying the code from the _ResourceGetAsString function above, which I had already used and knew worked well.

It might well be Vista (I am running x32 Home Premium), or more probably my understanding of the UDF. The code I am using to get the resource in and out is as follows:

#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, M:\Program\Au3 Scripts\Test\162.bin, rcdata, BIN_162, 0
...
...
; Load the 162 data from the saved resource
$data = _ResourceGetAsBytes("BIN_162")

Thanks for producing the UDF. I do hope it is an easy fix - like pointing out my error and smacking me over the head!

M23

@Melba23

Sorry but it's not possible to simply use your fix generally

because my another UDF functions expect this function will return structure of bytes (and not directly bytes).

I don't know simple solution for now without rewritting too much of other code :-(

Link to comment
Share on other sites

  • Moderators

@Zedna,

I hope you do not mind, but I have been playing with your UDF a little more.

The only other time I could find _ResourceGetAsBytes used was as a call from within _ResourceSaveToFile, which as you stated does expect a structure and not bytes. If you replace the call with the code from the current GetAsBytes function, SaveToFile still works perfectly. Then you can add the Return DllStructGetData($struct, 1) line to the GetAsBytes function and the SaveToFile function is not affected.

So GetAsBytes would read:

; _ResourceGetAsBytes() doesn't work for RT_BITMAP type
; because _ResourceGet() returns hBitmap instead of memory pointer in this case
Func _ResourceGetAsBytes($ResName, $ResType = 10, $ResLang = 0, $DLL = -1); $RT_RCDATA = 10
    
    Local $ResPointer, $ResSize

    $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL)
    If @error Then Return SetError(1, 0, 0)
    $ResSize = @extended
    $struct = DllStructCreate("byte[" & $ResSize & "]", $ResPointer) <  Changed
    Return DllStructGetData($struct, 1) ; returns bytes           <  Lines

EndFunc

While SaveToFile would read:

Func _ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0, $DLL = -1); $RT_RCDATA = 10
    Local $ResStruct, $ResSize, $FileHandle
    
    If $CreatePath Then $CreatePath = 8; mode 8 = Create directory structure if it doesn't exist in FileOpen()

    If $ResType = $RT_BITMAP Then
       ; workaround: for RT_BITMAP _ResourceGetAsBytes() doesn't work so use _ResourceGetAsImage()
        $hImage = _ResourceGetAsImage($ResName, $ResType)
        If @error Then Return SetError(10, 0, 0)
        
       ; create filepath if doesn't exist
        $FileHandle = FileOpen($FileName, 2+16+$CreatePath)
        If @error Then Return SetError(11, 0, 0)
        FileClose($FileHandle)
        If @error Then Return SetError(12, 0, 0)
        
        _GDIPlus_ImageSaveToFile($hImage, $FileName)
        _GDIPlus_ImageDispose($hImage)

        $ResSize = FileGetSize($FileName)
    Else
       ; standard way
       ;$ResStruct = _ResourceGetAsBytes($ResName, $ResType, $ResLang, $DLL)    < old line calling GetAsBytes
    
      ; Added lines with old GetAsBytes code
    
       Local $ResPointer

       $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL)
       If @error Then Return SetError(1, 0, 0)
       $ResSize = @extended
       $ResStruct =  DllStructCreate("byte[" & $ResSize & "]", $ResPointer)
        
      ; Resume original code

        If @error Then Return SetError(1, 0, 0)
        $ResSize = DllStructGetSize($ResStruct)
        
        $FileHandle = FileOpen($FileName, 2+16+$CreatePath)
        If @error Then Return SetError(2, 0, 0)
        FileWrite($FileHandle, DllStructGetData($ResStruct, 1))
        If @error Then Return SetError(3, 0, 0)
        FileClose($FileHandle)
        If @error Then Return SetError(4, 0, 0)
    EndIf

    Return $ResSize
EndFunc

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Or Create a func and a wrapper func :mellow:

-Old Function renamed to _ResourceGetAsByteStruct(...)

- wrapper:

Func _ResourceGetAsBytes(...)
   Local $struct = _ResourceGetAsByteStruct(...)
   if @error Then Return Seterror(@error,@extended,0)
   Return DllStructGetData($struct,1)
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Is there any way to inject a process into another process? For example to hack games people inject .dll files which have some sort of end effect (i would assume this is like multi-threading however giving the DLL access to the inter workings of the game allowing for wall hacks, and other such effects) So is there anyway to inject and executable the way you would a DLL??

Link to comment
Share on other sites

Is there a way to embed an UniCode saved tekst file ? Ansi coded text files works perfect ...

Try this:

Func _ResourceGetAsStringUnicode($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResPointer, $ResSize, $struct

    $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL)
    If @error Then
        SetError(1, 0, 0)
        Return ''
    EndIf
    $ResSize = @extended
    $struct = DllStructCreate("wchar[" & $ResSize & "]", $ResPointer)
    Return DllStructGetData($struct, 1) ; returns string
EndFunc

and tell me the result. If it works I will add it in my UDF.

Link to comment
Share on other sites

Another thing which i would really like in this UDF ..

Something like this -> _ResourceGetAsArray (Also Unicode)

Basicly the same as _FileReadToArray only from memory

Just use this:

$string =  _ResourceGetAsString(...); or _ResourceGetAsStringUnicode()
$array = StringSplit($string,'')
Edited by Zedna
Link to comment
Share on other sites

  • 2 weeks later...

Hi Zedna,

Your latest (two) versions with the unicode support will not run on Windows 2000

it will create an application error when starting

Best regards,

Emiel

I have created little test for ANSI/Unicode texts and it works fine for me on WINXP.

I will test it also on my WIN98SE (with installed MSLU). --> works fine too.

I suppose you haven't installed Microsoft Layer for Unicode (MSLU) 

http://msdn.microsoft.com/library/default...._me_systems.asp

http://msdn.microsoft.com/en-us/magazine/cc301794.aspx

I'm not sure about WIN 2000 maybe MSLU must be installed on them too.

Test code:

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, test_1.txt, rcdata, TEST_TXT_1, 0
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, test_2.txt, rcdata, TEST_TXT_2, 0
#AutoIt3Wrapper_run_after=upx.exe --best --compress-resources=0 "%out%"

#include "resources.au3"
 
$gui = GUICreate("Data from resources example",820,400)
$label1 = GUICtrlCreateLabel("",20,20,380,100)
$label2 = GUICtrlCreateLabel("",20,200,380,100)
GUISetState(@SW_SHOW)

; get string from resource
$string = _ResourceGetAsString("TEST_TXT_1")
GUICtrlSetData($label1, $string)

; get Unicode string from resource
GUICtrlSetData($label2, _ResourceGetAsStringW("TEST_TXT_2"))

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

Text files:

test_1.txttest_2.txt

EDIT:

Tested it also on my WIN98SE (with installed MSLU). --> works fine too.

EDIT2:

Try to instal GDI+ redistributable on your WIN2000.

http://www.microsoft.com/downloads/details...;displaylang=en

I think it will be GDI+ related because I call _GDIPlus_Startup() at begin of my UDF

which is sure source of problems in that case.

Edited by Zedna
Link to comment
Share on other sites

Hi Zedna,

Indeed ..the missing GDIplus.dll is the source of the problem..

Is there no other way ? to allow Unicode files without GDI+

Thnx

Emiel

It has nothing to do with Unicode.

I use GDI+ for images (other than BMP). Look at sources of my UDF.

If you don't use JPG,PNG,GIF images then just remove all GDI+ stuff and use this modified UDF (without GDI+).

Edited by Zedna
Link to comment
Share on other sites

Hi Zedna,

Indeed ..the missing GDIplus.dll is the source of the problem..

Is there no other way ? to allow Unicode files without GDI+

Thnx

Emiel

Simpler solution is to copy missing GDIplus.dll into C:\Windows\System32\ directory (or instal gdiplus_dnld.exe) on WIN2000 stations.

Then you can use my original UDF without any problems (on such stations).

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