Jump to content

Resources UDF


Zedna
 Share

Recommended Posts

Zedna, your UDF is really useful. One question... How to get the file version of the included file? I would like to compare the version of SQLite3.dll files (compare the file distributed with application and a dll installed on the client PC).

Link to comment
Share on other sites

Zedna, your UDF is really useful. One question... How to get the file version of the included file? I would like to compare the version of SQLite3.dll files (compare the file distributed with application and a dll installed on the client PC).

I don't know how to do this but fileversion of your resource DLL file is known at compile time so you can check it manually (or by some helper script) before compile time and store this information (as string) in global variable and later at runtime just compare DLL version installed on client PC against this stored global version string.

Link to comment
Share on other sites

#Include <WinAPIEx.au3>

$hDll = _WinAPI_GetModuleHandle('sqlite3.dll')
If Not $hDll Then
    $hDll = _WinAPI_LoadLibrary('sqlite3.dll')
EndIf
$sPath = _WinAPI_GetModuleFileNameEx(_WinAPI_GetCurrentProcess(), $hDll)
$sVer = FileGetVersion($sPath)

ConsoleWrite($sVer & @CR)

Link to comment
Share on other sites

Zedna, I'm sorry, but I have another question about _ResourceSaveToFile function. I'm trying to install a file to a folder with administrator privileges only. Compiled file running as administrator will install fine, but without an administrator nothing happens. The function below returns always the same result.

Func installResourceFile($sDestFile, $sResName, $sResType=10, $ResLang=0, $CreatePath=1, $DLL = -1)
    ; get filesize first
    _ResourceGet($sResName, $sResType, $ResLang, $DLL)
    If @error Then Return -1
    Local $filesize = @extended
    If $filesize = 0 Then Return -2
    Local $result = _ResourceSaveToFile($sDestFile,$sResName,$sResType,$ResLang,$CreatePath,$DLL)
MsgBox(0, '$result', $result) ; <<-- ??
    If @error Then
MsgBox(0, 'Error', 'Some error')    ; <<-- ??
        Return -1
    EndIf
    While 1
        If FileExists($sDestFile) And FileGetSize($sDestFile) = $filesize Then ExitLoop
        Sleep(100)
    WEnd
    Return 1
EndFunc ; ==>> installResourceFile

I do not want to run the application as admin and I'll have to check the user right of each folder before installing each file. Is there the possibility to return different values ​​for successful and unsuccessful _ResourceSaveToFile?

#Include <WinAPIEx.au3>

$hDll = _WinAPI_GetModuleHandle('sqlite3.dll')
If Not $hDll Then
    $hDll = _WinAPI_LoadLibrary('sqlite3.dll')
EndIf
$sPath = _WinAPI_GetModuleFileNameEx(_WinAPI_GetCurrentProcess(), $hDll)
$sVer = FileGetVersion($sPath)

ConsoleWrite($sVer & @CR)

Yashied, I meant to get a file version of DLL that is included as resource only:

Yashied, I meant to get a file version of DLL that is included as resource only:

#...
#AutoIt3Wrapper_Res_File_Add=resources\SQLite3.dll, rt_rcdata, SQL_FILE_1
#AutoIt3Wrapper_Res_File_Add=resources\SQLite3_x64.dll, rt_rcdata, SQL_FILE_2
#...
Link to comment
Share on other sites

Zedna, I'm sorry, but I have another question about _ResourceSaveToFile function. I'm trying to install a file to a folder with administrator privileges only. Compiled file running as administrator will install fine, but without an administrator nothing happens. The function below returns always the same result.

...
Local $result = _ResourceSaveToFile($sDestFile,$sResName,$sResType,$ResLang,$CreatePath,$DLL)
MsgBox(0, '$result', $result) ; <<-- ??
If @error Then
MsgBox(0, 'Error', 'Some error') ; <<-- ??
Return -1
EndIf
...

I do not want to run the application as admin and I'll have to check the user right of each folder before installing each file. Is there the possibility to return different values ​​for successful and unsuccessful _ResourceSaveToFile?

Try this:

...
Local $result = _ResourceSaveToFile($sDestFile,$sResName,$sResType,$ResLang,$CreatePath,$DLL)
If @error Then
  MsgBox(0, 'Error', 'Some error: ' & @error & @CRLF & 'return value: ' & $result) ; result should be 0
  Return -1
Else
  MsgBox(0, '$result', $result) ; result should be <> 0
EndIf
...

You can also use return value which is 0 at error or FileSize when all is OK.

EDIT: Your MsgBox immediatelly after calling _ResourceSaveToFile() reset @error to zero.

Edited by Zedna
Link to comment
Share on other sites

The problem is that _ResourceSaveToFile() return no error when installing to a system folder without authorization.

...
_ResourceSaveToFile($sDestFile,$sResName,$sResType,$ResLang,$CreatePath,$DLL)
If @error Then
   Return -1
EndIF
...

So before installation I have to check with an external function if destination folder is writable.

Link to comment
Share on other sites

The problem is that _ResourceSaveToFile() return no error when installing to a system folder without authorization.

...
_ResourceSaveToFile($sDestFile,$sResName,$sResType,$ResLang,$CreatePath,$DLL)
If @error Then
Return -1
EndIF
...

According to simplified source of _ResourceSaveToFile():

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()

; standard way
$ResStruct = _ResourceGetAsBytes($ResName, $ResType, $ResLang, $DLL)
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)

Return $ResSize
EndFunc

it seems there is problem/bug in FileOpen() which probably don't return @error

So this problem probably is not related to resources/my UDF but directly to AutoIt.

In _ResourceSaveToFile() there are correctly checked/handled all @error states after FileOpen/FileWrite/FileClose.

Try small testing script to check if my doubt is correct:

$FileHandle = FileOpen('c:\your system path', 2+16+$CreatePath)
If @error Then ...

Also problem may be in using parameter 8 (CreatePath) in FileOpen for system directory, try it without this parameter.

Link to comment
Share on other sites

Yes, you're right. The problem is in the FileOpen() function, which returns no error.

#include <File.au3>

Local $sTmpFile = _TempFile(@SystemDir)

$hFile = FileOpen($sTmpFile, 2 + 8 + 16)
If @error Then
    MsgBox(0, "Error handle", "An error while opening file.")    ; <<-- this message does not show
    Exit
EndIf

If $hFile = -1 Then
    MsgBox(0, "Error", "Unable to open file.")                  ; <<-- this message always appears
    Exit
EndIf

FileClose($sTmpFile)

What about change the causing line in _ResourceSaveToFile():

; ...
$FileHandle = FileOpen($FileName, 2+16+$CreatePath)
If @error Then Return SetError(2, 0, 0)
; ...

to

; ...
$FileHandle = FileOpen($FileName, 2+16+$CreatePath)
If $FileHandle = -1 Then Return SetError(2, 0, 0)
; ...

And maybe the line with FileWrite() function...

Edited by Logman
Link to comment
Share on other sites

What about change the causing line in _ResourceSaveToFile():

; ...
$FileHandle = FileOpen($FileName, 2+16+$CreatePath)
If @error Then Return SetError(2, 0, 0)
; ...

to

; ...
$FileHandle = FileOpen($FileName, 2+16+$CreatePath)
If $FileHandle = -1 Then Return SetError(2, 0, 0)
; ...

Yes. You are right.

Now I'm looking into AutoIt's helpfile and there is really no @error set when error occurs at FileOpen()

it just returns -1 as return value.

So my Func _ResourceSaveToFile() must be fixed this way:

Func _ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResStruct, $ResSize, $FileHandle, $ret

    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 $FileHandle = -1 Then Return SetError(11, 0, 0)
        $ret = FileClose($FileHandle)
        If $ret = 0 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)
        If @error Then Return SetError(1, 0, 0)
        $ResSize = DllStructGetSize($ResStruct)

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

    Return $ResSize
EndFunc

Thanks for finding bug in my Resources UDF :-)

Link to comment
Share on other sites

  • 2 weeks later...

Today I discovered problem/bug in my Resources UDF (in one of my projects using it).

In application with more than one GUI I used

_ResourceSetImageToCtrl($button_xx, "BMP_XX", $RT_BITMAP)

for setting bitmap image to this button.

In compiled EXE image wasn't shown and problem was in resources.au3 in Func _SetBitmapToCtrl($CtrlId, $hBitmap)

Code

$CtrlId = _WinAPI_GetDlgCtrlID($hWnd) ; support for $CtrlId = -1

returned strange data and later

_WinAPI_GetClassName($CtrlId)

returned "IME" instead of expected "Button" ClassName.

I don't know exact reason why this problem occured but quick hack/workaround is to use

in resources.au3 in Func _SetBitmapToCtrl($CtrlId, $hBitmap)

instead of original

$CtrlId = _WinAPI_GetDlgCtrlID($hWnd) ; support for $CtrlId = -1
If @error Then Return SetError(2, 0, 0)

this fixed code

If $CtrlId = -1 Then ; workaround here <---
$CtrlId = _WinAPI_GetDlgCtrlID($hWnd) ; support for $CtrlId = -1
If @error Then Return SetError(2, 0, 0)
EndIf

So if I don't use -1 as Control Id then this problem will not occur.

Link to comment
Share on other sites

_ResourceGetAsBitmap

Return _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_ResourcePlaySound

If $DLL <> -1 The
        _WinAPI_FreeLibrary($hInstance)
        If @error Then Return SetError(2, 0, 0)
    EndIf

Can't make the examples without compiling - _ResourceSaveToFile, _ResourceGetAsString, _ResourceGetAsStringW

Edited by AZJIO
Link to comment
Share on other sites

  • 3 months later...

Hi all

I tried the examples today and finally got it working after looking back in this thread.

However when i compile/build our program i use the command line to call the wrapper program so i am wondering what the difference is between using Compile (which doesnt seem to work from right click context menu) and Build (from Scite) and how that would effect my command line call to AutoIT Wrapper as i would really like to use this UDF?

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

DOTCOMmunications,

Zedna has not been around for a while so I hope you do not mind me replying. :)

Within SciTE the 2 options work like this - assuming you are using the full SciTE4AutoIt3 install:

- Compile - brings up a dialog where you can set various compile options.

- Build - compiles using the existing AutoIt3Wrapper directives in the script.

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

  • 2 weeks later...

Hello, I've got a question regarding tray icons. There have been some examples in here regarding it but nothing only around the question.

I've searched but either not understood or found anything definitive, thus I've decided to post.

I'd like to have embedded icons in my compiled executable, that I can then call in my script to change the tray icon between

Do not want to use a temporary folder and do not use any GUI, only a tray icon.

How do I add the icons into my file for tray use and how do I call them without saving them temporary on the computer?

Link to comment
Share on other sites

Look at this >>

You will find plenty of examples around the Forum.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 3 months later...

I have been searching but was unable to find anything specific to this situation. Basically I want to add an icon file to my script and then use the icon resource in FileCreateShortcut() when I run the script. Is this possible?

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