Jump to content

ResHacker project


trancexx
 Share

Recommended Posts

  • 3 weeks later...

Can't believe I haven't tried to compile this project yet, but this section

If @Compiled Then
    Switch $sParent
        Case "explorer.exe"
            $iDroppedOnFirstRun = $CmdLineRaw = True
            _Main(StringReplace($CmdLineRaw, '"', ''))
        Case Else
            _ExecuteCommandLine()
    EndSwitch
Else
    _Main()
EndIf

doesn't work at all if you launch from a 3rd party file manager, it just exits right away since _ExecuteCommandLine() doesn't do anything yet. I'm not sure what you're after with the 'explorer.exe' parent test... I just changed it to test 'If $CmdLine[0] Then...' to test if a file was dropped or if it was launched from command line with a file path.

Link to comment
Share on other sites

Can't believe I haven't tried to compile this project yet, but this section

If @Compiled Then
    Switch $sParent
        Case "explorer.exe"
            $iDroppedOnFirstRun = $CmdLineRaw = True
            _Main(StringReplace($CmdLineRaw, '"', ''))
        Case Else
            _ExecuteCommandLine()
    EndSwitch
Else
    _Main()
EndIf

doesn't work at all if you launch from a 3rd party file manager, it just exits right away since _ExecuteCommandLine() doesn't do anything yet. I'm not sure what you're after with the 'explorer.exe' parent test... I just changed it to test 'If $CmdLine[0] Then...' to test if a file was dropped or if it was launched from command line with a file path.

_ExecuteCommandLine() do. It writes to STDERR and STDOUT.

About "explorer.exe" part. I wanted not to show GUI if launched with anything except explorer. For example it can be run like Run("Resources.exe") with any application. In that case $CmdLine[0] is 0 and in your case GUI mode would go. I don't want that.

It maybe a bit lame now (3rd party file manager you say), but I'm open to new suggestions.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

So you're trying to prevent other applications from running the app? The _ExecuteCommandLine() function just prints the command line to STDOUT and an 'under construction' message to STDERR. I don't see the purpose as of yet, that would make you want to disable any other applications from launching your app. I guess I don't understand your goal, other than to stop it from running, if it is launched by another process (another file manager, another script, etc.).

Link to comment
Share on other sites

So you're trying to prevent other applications from running the app? The _ExecuteCommandLine() function just prints the command line to STDOUT and an 'under construction' message to STDERR. I don't see the purpose as of yet, that would make you want to disable any other applications from launching your app.

No. I meant for other applications to run it as command line tool. GUI isn't needed for that.

I guess I don't understand your goal, other than to stop it from running, if it is launched by another process (another file manager, another script, etc.).

And now?

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Ok, I gotcha. I misinterpreted your meaning of command line tool. I thought you meant to launch it from the command line and open the GUI to the specified file. But what you mean is a total command line functionality, like ResHacker. Cool. I've hacked around it for my needs.

I know I've said it before, but this is a great project :D

Link to comment
Share on other sites

  • 5 months later...

Hi, trancexx!

I'm having some problems with loading png image from dll created with your ResHacker. Can you explain how?

That script is doing it. Just look in there.

#include <WinAPI.au3>
#include <Memory.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>
#include <Constants.au3>

Opt("MustDeclareVars", 1)

Global Const $STM_SETIMAGE = 370


GUICreate("TestPNG")



Global $bBinary = _ResourceGetAsRaw("YourResource.dll", "PNG", 1) ; PNG is type and number 1 is name
Global $iWidth, $iHeight
Global $hPNG = _CreateHBitmapFromBinaryImage($bBinary, $iWidth, $iHeight)

Global $hPicControl = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight)
ConsoleWrite($iWidth & " x " & $iHeight & @CRLF)

_WinAPI_DeleteObject(GUICtrlSendMsg($hPicControl, $STM_SETIMAGE, 0, $hPNG))
_WinAPI_DeleteObject($hPNG)


GUISetState()


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




Func _ResourceGetAsRaw($sModule, $vResType, $vResName, $iResLang = 0)

    Local $hResDll = _WinAPI_LoadLibraryEx($sModule, $LOAD_LIBRARY_AS_DATAFILE)
    If @error Then Return SetError(1, 0, 0)

    Local $sTypeType = "wstr"
    If IsNumber($vResType) Then $sTypeType = "int"

    Local $sNameType = "wstr"
    If IsNumber($vResName) Then $sNameType = "int"

    Local $aCall = DllCall("kernel32.dll", "handle", "FindResourceExW", _
            "handle", $hResDll, _
            $sTypeType, $vResType, _
            $sNameType, $vResName, _
            "int", $iResLang)
    If @error Or Not $aCall[0] Then
        _WinAPI_FreeLibrary($hResDll)
        Return SetError(2, 0, 0)
    EndIf

    Local $hResource = $aCall[0]

    $aCall = DllCall("kernel32.dll", "int", "SizeofResource", "handle", $hResDll, "handle", $hResource)
    If @error Or Not $aCall[0] Then
        _WinAPI_FreeLibrary($hResDll)
        Return SetError(3, 0, 0)
    EndIf

    Local $iSizeOfResource = $aCall[0]

    $aCall = DllCall("kernel32.dll", "handle", "LoadResource", "handle", $hResDll, "handle", $hResource)
    If @error Or Not $aCall[0] Then
        _WinAPI_FreeLibrary($hResDll)
        Return SetError(4, 0, 0)
    EndIf

    $hResource = $aCall[0]

    $aCall = DllCall("kernel32.dll", "ptr", "LockResource", "handle", $hResource)
    If @error Or Not $aCall[0] Then
        _WinAPI_FreeLibrary($hResDll)
        Return SetError(5, 0, 0)
    EndIf

    Local $pResource = $aCall[0]

    Local $tBinary = DllStructCreate("byte[" & $iSizeOfResource & "]", $pResource)
    Local $bBinary = DllStructGetData($tBinary, 1)

    _WinAPI_FreeLibrary($hResDll)

    Return $bBinary

EndFunc   ;==>_ResourceGetAsRaw



Func _CreateHBitmapFromBinaryImage($bBinary, ByRef $iWidth, ByRef $iHeight)

    Local $iSize = BinaryLen($bBinary)

    Local $hMemGlobal = _MemGlobalAlloc($iSize, $GMEM_MOVEABLE)
    If @error Then Return SetError(1, 0, 0)

    Local $pMemory = _MemGlobalLock($hMemGlobal)
    If @error Then
        _MemGlobalFree($hMemGlobal)
        Return SetError(2, 0, 0)
    EndIf

    Local $tBinary = DllStructCreate("byte[" & $iSize & "]", $pMemory)
    DllStructSetData($tBinary, 1, $bBinary)

    Local $aCall = DllCall("ole32.dll", "long", "CreateStreamOnHGlobal", _
            "handle", $pMemory, _
            "int", 1, _ ; automatically free
            "ptr*", 0)

    If @error Or $aCall[0] Then
        _MemGlobalFree($hMemGlobal)
        Return SetError(3, 0, 0)
    EndIf

    Local $pStream = $aCall[3]

    _MemGlobalUnlock($pMemory)
    If @error Then Return SetError(4, 0, 0)

    _GDIPlus_Startup()
    $aCall = DllCall($ghGDIPDll, "dword", "GdipCreateBitmapFromStream", _
            "ptr", $pStream, _
            "ptr*", 0)

    If @error Or $aCall[0] Then
        _GDIPlus_Shutdown()
        _MemGlobalFree($hMemGlobal)
        Return SetError(5, 0, 0)
    EndIf

    Local $pBitmap = $aCall[2]

    $aCall = DllCall($ghGDIPDll, "dword", "GdipGetImageDimension", _
            "handle", $pBitmap, _
            "float*", 0, _
            "float*", 0)

    If @error Or $aCall[0] Then
        _GDIPlus_ImageDispose($pBitmap)
        _GDIPlus_Shutdown()
        _MemGlobalFree($hMemGlobal)
        Return SetError(6, 0, 0)
    EndIf

    $iWidth = $aCall[2]
    $iHeight = $aCall[3]

    Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    If @error Then
        _GDIPlus_ImageDispose($pBitmap)
        _GDIPlus_Shutdown()
        _MemGlobalFree($hMemGlobal)
        Return SetError(7, 0, 0)
    EndIf

    _GDIPlus_ImageDispose($pBitmap)
    _GDIPlus_Shutdown()
    _MemGlobalFree($hMemGlobal)

    Return $hBitmap

EndFunc   ;==>_CreateHBitmapFromBinaryImage

And how can I play wave sound from the same dll?

Search forums(web) with PlaySound.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I found this:

#include <WinAPI.au3>

_ResourcePlaySound("TEST_SOUND", 0, "test.dll")
Func _ResourcePlaySound($ResName, $Flag = 0, $DLL = -1)
    If $DLL = -1 Then
        $hInstance = 0
    Else
        $hInstance = _WinAPI_LoadLibrary($DLL)
    EndIf
    Local $ret = DllCall("winmm.dll", "int", "PlaySound", "str", $ResName, "hwnd", $hInstance, "int", BitOr(0x00040004, $Flag))
    If @error Then Return SetError(1, 0, 0)
    If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance)
    If @error Then Return SetError(2, 0, 0)
    Return $ret[0]
EndFunc

but it won't play sounds. I don't know what's wrong with it.

PlaySound plays SOUND or WAVE res types (that order).

When you are adding music resource choose one of those two res types (that means don't use predefined values for res types).

Plus that function you found is not checking whether string or number is passed as resource name.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

trancexx can you post an example of use RT_RCDATA resource from a dll created with your script?

RT_RCDATA can contain any type of resource. You know what yours should be?

ResourcesViewerAndCompiler.au3 script is using special algorithm (this sounds smarter than it is) to determine the real type of RT_RCDATA resource. It's all matter of interpretation.

In all cases the basic function is _ResourceGetAsRaw() to get raw binary that is interpreted later.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Yes, I know what type of resource I have. I have a text file loaded as RT_RCDATA resource.

If I check with your Resource viewer after dll is created all looks good. When I try to use this resource I tried this code:

$BIN = _ResourceGetAsRaw(@ScriptDir & "\Test.dll","RT_RCDATA","TEST")
If @error Then 
   MsgBox(0,"Error",@error)
Else
   MsgBox(0,"Resource",$BIN)
EndIf

Dll name is Test.dll, and resource name is TEST. I do something wrong? I got all time error 2 (this mean FindResourceExW fail, right?).

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Yes, I know what type of resource I have. I have a text file loaded as RT_RCDATA resource.

If I check with your Resource viewer after dll is created all looks good. When I try to use this resource I tried this code:

$BIN = _ResourceGetAsRaw(@ScriptDir & "\Test.dll","RT_RCDATA","TEST")
If @error Then 
   MsgBox(0,"Error",@error)
Else
   MsgBox(0,"Resource",$BIN)
EndIf

Dll name is Test.dll, and resource name is TEST. I do something wrong? I got all time error 2 (this mean FindResourceExW fail, right?).

If you are using the function from few posts above, you should know that it's using "handle" DllCall() type as one of the parameters type. If your AutoIt is older it will fail. Change that type to "ptr" or update AutoIt.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I just update my AutoIt to version v3.3.6.0 and beta v3.3.5.6 but the problem is the same.

I tried also to change dll call type from handle to ptr without any result.

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

I just update my AutoIt to version v3.3.6.0 and beta v3.3.5.6 but the problem is the same.

I tried also to change dll call type from handle to ptr without any result.

Replace "RT_RCDATA" with number 10.

So, it should be:

;Global Const $RT_RCDATA = 10
$BIN = _ResourceGetAsRaw(@ScriptDir & "\Test.dll", 10, "TEST")
If @error Then 
   MsgBox(0,"Error",@error)
Else
   MsgBox(0,"Resource",$BIN)
EndIf

Otherwise function is looking for "RT_RCDATA" type (literally).

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 5 months later...

This script is brilliant. How did I miss out on it? I love it already and I only downloaded it a few minutes ago.

I see the function _ExecuteCommandLine is still under construction, so I suppose it's still open for suggestions.

How about passing an .rc file to compile a dll with the resources just listed, much like c++

Num1Green ICON "icons\\Num1Green.ico"
Num1Grey ICON "icons\\Num1Grey.ico"
Num1Yellow ICON "icons\\Num1Yellow.ico"
Num2Green ICON "icons\\Num2Green.ico"
Num2Grey ICON "icons\\Num2Grey.ico"
Num2Yellow ICON "icons\\Num2Yellow.ico"
Num3Green ICON "icons\\Num3Green.ico"
Num3Grey ICON "icons\\Num3Grey.ico"
Num3Yellow ICON "icons\\Num3Yellow.ico"
..... or
FeedBkWarning BITMAP DISCARDABLE "fb_Warn.bmp"
FeedBkErrors BITMAP DISCARDABLE "fb_OK.bmp"
FeedBkErrors BITMAP DISCARDABLE "fb_error.bmp"
..... or
fWarning BITMAP "fb_Warn.bmp"
fErrors BITMAP "fb_OK.bmp"
fErrors BITMAP "fb_error.bmp"

Only a thought for batch processing.

Link to comment
Share on other sites

Thanks ivan.

I made a promise to my self, some time ago, I won't update this script until dl count is over a certain number.

Most of the script is rewritten by now to be more robust, clean, fast, reliable, wider, everything...

What you run is very old version. If you like that one, you will love the new one.

But, a promise is a promise.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Thanks ivan.

I made a promise to my self, some time ago, I won't update this script until dl count is over a certain number.

Most of the script is rewritten by now to be more robust, clean, fast, reliable, wider, everything...

What you run is very old version. If you like that one, you will love the new one.

But, a promise is a promise.

You're just too kind, developing, sharing + providing support. I love your script because I can simply add files with the fileopendialog, and it does the rest. Just save it and ready!!!

I'm trying to figure out how this script works, though, but it's just way over my head. I'm trying to build an array to match icon ordinals and icon names from a dll I built in c++ (now I can do it with your script... ;) ), and the solution to my problem is somewhere here :). I just can't see it. I'm not giving up yet, but if I do, would you mind pointing me in the right direction?

Thnx. Can't wait to see the next version.

Edited by ivan
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...