Jump to content

Resources UDF


Zedna
 Share

Recommended Posts

not tested:

Const $FORMAT_MESSAGE_FROM_HMODULE = 0x0800
Const $FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x0100

$tBuffer = DllStructCreate("wchar[1]") ; I'm not sure here about the size/type of buffer, buffer will be auto alocated
$pBuffer = DllStructGetPtr($tBuffer)
$iFlags = BitOr($FORMAT_MESSAGE_FROM_HMODULE, $FORMAT_MESSAGE_ALLOCATE_BUFFER)
$MessageID = 1 ; Id of message you want to get, replace by your desired number
$iLanguageID = 0 ; neutral lang

$hModule = _WinAPI_LoadLibrary(@SystemDir & "\ntoskrnl.exe") ; path to your EXE/DLL module
_WinAPI_FormatMessage($iFlags, $hModule, $iMessageID, $iLanguageID, $pBuffer, 0, 0)

MsgBox(4096, "Read BSOD", DllStructGetData($tBuffer,1))

still not working...

$tBuffer = DllStructCreate("wchar[65536]")
$pBuffer = DllStructGetPtr($tBuffer)
$iMessageID = 1
$iLanguageID = 0

$hModule = _WinAPI_LoadLibrary(@SystemDir & "\ntoskrnl.exe")
_WinAPI_FormatMessage(0x0800, $hModule, $iMessageID, $iLanguageID, $pBuffer, "65536", 0)

MsgBox(4096, "Read BSOD", DllStructGetData($tBuffer,1))

Ciao.

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...
  • 2 weeks later...

You don't need reshacker anymore, it now uses the AutoItWrapper program that's included with SciTE4AutoIt3. I think you need to look at the first post again.

Edited by guinness

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

Ah, thanks :) Something obvious!

Well, now it does better but not perfect though, I get errors during compiling:

!>23:03:25 Error: EndUpdateResource: Returncode = 0 - LastError:110:The system cannot open the device or file specified.rc:2

!>23:03:25 Error: Program Resource updating Failed. The output program will not contain the Resource updates!rc:2

/edit

Okay, got it fixed with this thread:

Edited by Armag3ddon
Link to comment
Share on other sites

  • 1 month later...

Hi, Zedna

Can you show me how to load an animated cursor (.ani) directly from exe? I can load it from external file but I want it to be available from compiled script as resource. This is what I have so far:

#AutoIt3Wrapper_Res_File_Add=link.ani, 21, cursor

#include <resources.au3>

If Not @Compiled Then
    $sCurFile = @ScriptDir & "link.ani"
    Global $aCur = DllCall("user32.dll", "int", "LoadCursorFromFile", "str", $sCurFile)
    If $aCur[0] = "" Then Exit MsgBox(262144 + 16, "", "Cursor file " & $sCurFile & " not found")
Else
    ; LOAD CURSOR FROM EXE
EndIf

GUISetState()

Global $hGui = GUICreate("Chosen Cursor", 300, 200)
GUICtrlCreateLabel("dadadadadada", 10, 10, 200, 25)
GUISetState()

GUIRegisterMsg(0x0020, 'WM_SETCURSOR')

Do
    Sleep(10)
Until GUIGetMsg() = -3

Func WM_SETCURSOR($hWnd, $iMsg, $iWParam, $iLParam)
    If $hWnd = $hGui Then
    DllCall("user32.dll", "int", "SetCursor", "int", $aCur[0])
    Return 1
    EndIf
EndFunc ;==>WM_SETCURSOR

Thanks,

Playlet

hi playlet!

i just wanted to ask, have you found a way to do it, and if so, can you please describe it for me? =)

If not could anyone help me with this please?

as i saw on MSDN, the LoadCursor function requires an instance of the exe from which i want to get the cursor resource, and a string as identifier (can be used also an integer index instead?)

and sorry for bad grammar ^^

Edited by Morgyone
Link to comment
Share on other sites

as i saw on MSDN, the LoadCursor function requires an instance of the exe from which i want to get the cursor resource, and a string as identifier (can be used also an integer index instead?)

Here is my testing script which should work but it doesn't.

It works only with loading cursor from external EXE resource (totalcmd.exe).

It seems that cursors added by Au3Wrapper directive are corrupted (seen by reshacker after compilation) and that the reason of problems.

I will play with it more later ...

Maybe Jos can test why cursors added by

#AutoIt3Wrapper_Res_File_Add=pen_il.cur, rt_cursor, CUR_1

are corrupted?

; cursors from Win7
;~ #AutoIt3Wrapper_Res_File_Add=aero_link.cur, rt_cursor, CUR_1
;~ #AutoIt3Wrapper_Res_File_Add=aero_busy.ani, rt_anicursor, ANI_CUR_1

; cursors from Win XP
#AutoIt3Wrapper_Res_File_Add=pen_il.cur, rt_cursor, CUR_1
#AutoIt3Wrapper_Res_File_Add=banana.ani, rt_anicursor, ANI_CUR_1

#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n

#include <GuiConstants.au3>
#include <WinAPI.au3>

Global $hInstance
Global $hCursor
Global $gui

$gui = GUICreate("Cursor from resources example",820,400)
$label1 = GUICtrlCreateLabel("abc def",20,320,380,100)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SETCURSOR, 'WM_SETCURSOR')

;~ $hInstance = _WinAPI_GetModuleHandle("") ; doesn't work
$hInstance = _WinAPI_LoadLibraryEx('totalcmd.exe', $LOAD_LIBRARY_AS_DATAFILE) ; work OK

;~ $hCursor = _WinAPI_LoadCursor($hInstance, 'CUR_1') ; doesn't work
$hCursor = _WinAPI_LoadCursor($hInstance, 1) ; work OK
If @error Then
    MsgBox(0, '_WinAPI_LoadCursor','error1 CUR')
    Exit
EndIf

;~ $hCursor = _WinAPI_LoadCursor($hInstance, 'ANI_CUR_1')
;~ If @error Then
;~     MsgBox('_WinAPI_LoadCursor','error2 ANI')
;~     Exit
;~ EndIf

_WinAPI_SetCursor($hCursor)

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

Func WM_SETCURSOR($hWnd, $iMsg, $iWParam, $iLParam)
    If $hWnd = $gui Then
        _WinAPI_SetCursor($hCursor)
        Return 0
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Func _WinAPI_LoadCursor($hInstance, $sCursor)
    Local $aResult, $sType = "int"

    If IsString($sCursor) Then $sType = "str"
    $aResult = DllCall("User32.dll", "hwnd", "LoadCursor", "hwnd", $hInstance, $sType, $sCursor)
    _WinAPI_Check("_WinAPI_LoadCursor", ($aResult[0] = 0), 0, True)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_LoadCursor
Link to comment
Share on other sites

Really strange. UPX should leave the resources accessible.

Edit: AutoIt3Wrapper misses handling for RT_CURSOR and RT_CURSOR_GROUP resources. Here is a description of the required format: http://www.devsource.com/c/a/Architecture/Resources-From-PE-I/2/

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

I took a look at the link, and I'll take a shot at adding support for the cursor types to AutoIt3Wrapper. No ETA obviously. One question from that description though... does a single cursor (ie NOT animated) still get a RT_GROUP_CURSOR entry with wNumImages = 1? I'm thinking the answer is yes.

Link to comment
Share on other sites

I took a look at the link, and I'll take a shot at adding support for the cursor types to AutoIt3Wrapper. No ETA obviously. One question from that description though... does a single cursor (ie NOT animated) still get a RT_GROUP_CURSOR entry with wNumImages = 1? I'm thinking the answer is yes.

Yes

wtfpl-badge-1.png

Link to comment
Share on other sites

Ok, give the attached versions of AutoIt3Wrapper a test. I've included an x86 and x64 version, and tested each when compiling both 32-bit and 64-bit exe's. It should have full support for cursors now. FYI, AutoIt3Wrapper doesn't support PNG compressed icons or cursors at the moment (Vista+).

Regarding RT_ANICURSOR and RT_ANIICON. These resources are stored as raw binary data, similar to RT_RCDATA. This is just how it is done, and you'll need to extract the resources to files to use them. If you can find any information to the contrary, please let me know.

You could pseudo work around this by storing your animated cursor as individual icons then manually animating them like an animated gif. I think trancexxx has done similar things, as well as some tray icon UDF somewhere. But that is beyond the scope of this thread and AutoIt3Wrapper.

Let me know how it goes and I'll get the changes to Jos.

Edit:

Apparently you CAN load an animated cursor from a resource. See Zedna's next post.

Edit 2:

Jos has merged the changes and uploaded the new version to the SciTE beta directory for everyone to download. Enjoy!

Edited by wraithdu
Link to comment
Share on other sites

... Let me know how it goes and I'll get the changes to Jos.

Thanks!!

Now I tested this new AutoIt3Wrapper and it works fine with standard cursors (.cur) and also with animated cursors (.ani)

It works fine also with cursors (also animated) from my Windows7.

Here is testing script:

; cursors from Win7
#AutoIt3Wrapper_Res_File_Add=aero_link.cur, rt_cursor, CUR_1
#AutoIt3Wrapper_Res_File_Add=aero_busy.ani, rt_anicursor, ANI_CUR_1
; cursors from Win XP
#AutoIt3Wrapper_Res_File_Add=3dsmove.cur, 1, CUR_2
#AutoIt3Wrapper_Res_File_Add=banana.ani, rt_anicursor, ANI_CUR_2

#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n

#include <GuiConstants.au3>
#include <WinAPI.au3>

$gui = GUICreate("Cursor from resources example",820,400)
$label1 = GUICtrlCreateLabel("abc def",20,320,380,100) ; controls in GUI with standard cursor
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SETCURSOR, 'WM_SETCURSOR')

$hInstance = _WinAPI_GetModuleHandle("")

$hCursor = _WinAPI_LoadCursor($hInstance, 'CUR_2')
_WinAPI_SetCursor($hCursor)

Sleep(5000)

$hCursor = _WinAPI_LoadCursor($hInstance, 'ANI_CUR_2')
_WinAPI_SetCursor($hCursor)

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

Func WM_SETCURSOR($hWnd, $iMsg, $iWParam, $iLParam)
    If $hWnd = $gui Then
        _WinAPI_SetCursor($hCursor)
        Return 0
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Func _WinAPI_LoadCursor($hInstance, $sCursor)
    Local $aResult, $sType = "int"

    If IsString($sCursor) Then $sType = "str"
    $aResult = DllCall("User32.dll", "hwnd", "LoadCursor", "hwnd", $hInstance, $sType, $sCursor)
    _WinAPI_Check("_WinAPI_LoadCursor", ($aResult[0] = 0), 0, True)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_LoadCursor

CURSORS.zip

Edited by Zedna
Link to comment
Share on other sites

Heh, that's awesome :oops: I had no idea you could load an animated cursor from a resource. All the research I did last night made it seem like you had to save it out to a file first. I'm curious if you found somewhere that was documented, or if you just tried it out.

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