Jump to content



Photo

Resources UDF


  • Please log in to reply
582 replies to this topic

#521 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 08 September 2011 - 01:30 AM

I found several problems in Resources.au3:

1. Trying to load resources from the external modules leads to crash the script because you call _WinAPI_FreeLibrary().
#Region #AutoIt3Wrapper_Res_File_Add=Silverlight.png, 10, TEST #EndRegion   #Include "Resources.au3"   GUICreate('', 256, 256) $Pic = GUICtrlCreatePic('', 64, 64, 128, 128) GUISetState()   FileCopy(@ScriptFullPath, @ScriptDir & 'Duplicate.exe', 1) _ResourceSetImageToCtrl($Pic, 'TEST', 10, @ScriptDir & 'Duplicate.exe')   Do Until GUIGetMsg() = -3


2. A memory leak.
#Region #AutoIt3Wrapper_Res_File_Add=Silverlight.png, 10, TEST #EndRegion   #Include "Resources.au3"   GUICreate('', 256, 256) $Pic = GUICtrlCreatePic('', 64, 64, 128, 128) GUISetState()   Run(@SystemDir & 'taskmgr.exe') MsgBox(0, '', '') For $i = 1 To 1000     _ResourceSetImageToCtrl($Pic, 'TEST') Next MsgBox(0, '', '')   Do Until GUIGetMsg() = -3


3. _ResourceSetImageToCtrl() does not fully supports transparent and semitransparent images such as .png. Because _GDIPlus_BitmapCreateHBITMAPFromBitmap() creates a DDB, but need to DIB. Just replace _GDIPlus_BitmapCreateHBITMAPFromBitmap() to _GDIPlus_BitmapCreateDIBFromBitmap()...

Posted Image Posted Image

AutoIt         
Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)       Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0       $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)     If (@error) Or ($Ret[0]) Then         Return 0     EndIf     $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)     $pBits = DllStructGetData($tData, 'Scan0')     If Not $pBits Then         Return 0     EndIf     $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword')     DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR))     DllStructSetData($tBIHDR, 2, $Ret[2])     DllStructSetData($tBIHDR, 3, $Ret[3])     DllStructSetData($tBIHDR, 4, 1)     DllStructSetData($tBIHDR, 5, 32)     DllStructSetData($tBIHDR, 6, 0)     $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)     If (Not @error) And ($hResult[0]) Then         DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $Ret[2] * $Ret[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))         $hResult = $hResult[0]     Else         $hResult = 0     EndIf     _GDIPlus_BitmapUnlockBits($hBitmap, $tData)     Return $hResult EndFunc   ;==>_GDIPlus_BitmapCreateDIBFromBitmap

Attached Thumbnails

  • Silverlight.png

Edited by Yashied, 08 September 2011 - 01:52 AM.






#522 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 08 September 2011 - 08:55 AM

@Yashied
Thanks!
I will definitely fix these bugs but I can't promise any date.

#523 DXRW4E

DXRW4E

    Adventurer

  • Active Members
  • PipPip
  • 131 posts

Posted 25 December 2011 - 11:21 AM

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.

#524 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 28 December 2011 - 10:38 PM

Hi!

How can I use swf file directly from executable in the script below without extracting it first?

AutoIt         
#AutoIt3Wrapper_Res_File_Add=file.swf, 10, MYSWFFILE #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $obj = ObjCreate("ShockwaveFlash.ShockwaveFlash") $GUI = GUICreate("Test", 160, 160) GUICtrlCreatePic("bg.bmp", 0, 0, 160, 160) GUICtrlSetState(-1,128) $GUI2 = GUICreate("", 160, 160, 0, 0, $WS_POPUP, $WS_EX_MDICHILD+$WS_EX_LAYERED, $GUI) GUISetBkColor(0x222211) $ActiveX = GUICtrlCreateObj( $obj, 40, 40, 80, 80) _WinAPI_SetLayeredWindowAttributes($GUI2,0x222211,100,0x01) With $obj     .bgcolor = "#222211"     .Movie = @ScriptDir & "\file.swf"; it should be loaded here, directly from compiled exe - no temporary files .Quality = 1     .ScaleMode = 2     .Loop = True     .wmode = "transparent" EndWith GUISetState(@SW_SHOW, $GUI) GUISetState (@SW_SHOW, $GUI2) While 1     If GUIGetMsg() = -3 Then         $obj = 0         GUIDelete()         Exit     EndIf WEnd


Required files: bmpBG-and-swf.zip

#525 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 28 December 2011 - 10:58 PM

Does the flash object allow you to play a swf directly from a resource? If so, then you need to consult the flash documentation.

Edited by wraithdu, 28 December 2011 - 10:58 PM.


#526 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 28 December 2011 - 11:00 PM

How can I use swf file directly from executable in the script below without extracting it first?


I don't know
but you can try similar approach as in my IE example with res:// syntax, see examples in resource.zip

#527 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 29 December 2011 - 11:57 PM

@wraithdu
I don't know...

@Zedna
No, it doesn't work

#528 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 14 January 2012 - 06:05 PM

Just for info:
I will be almost offline or totally offline for several weeks (maybe months?) so don't expect quick response these days from me ...

#529 Chad2

Chad2

    Seeker

  • Active Members
  • 20 posts

Posted 09 February 2012 - 06:10 PM

Just what I was looking for. Thanks. 5*

Edited by Chad2, 09 February 2012 - 06:10 PM.


#530 Armag3ddon

Armag3ddon

    Seeker

  • Active Members
  • 34 posts

Posted 20 February 2012 - 10:47 PM

Okay, what do I need to do to make this work? Even the examples aren't working. If put reshacker.exe everywhere. I must be missing something really obvious, everyone else can use this :I

#531 guinness

guinness

    guinness

  • MVPs
  • 10,299 posts

Posted 20 February 2012 - 10:50 PM

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, 20 February 2012 - 10:50 PM.

Example List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _DesktopDimensions() • _DisplayPassword() • _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() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _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() • _StringIsValid() • _StringReplaceWholeWord() • _StringStripChar() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • AutoIt Search • AutoIt3 Portable • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • FileInstallr • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIGetBkColor() • LockFile() • PasteBin • SciTE Jump • Signature Creator • WM_COPYDATA • More Examples...Updated: 11/04/2013


#532 Armag3ddon

Armag3ddon

    Seeker

  • Active Members
  • 34 posts

Posted 20 February 2012 - 11:05 PM

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: http://www.autoitscript.com/forum/topic/110339-error-endupdateresource-returncode-0-lasterror110/

Edited by Armag3ddon, 20 February 2012 - 11:18 PM.


#533 Morgyone

Morgyone

    Seeker

  • New Members
  • 2 posts

Posted 28 March 2012 - 08:20 PM

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:

AutoIt         
#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, 28 March 2012 - 08:31 PM.


#534 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 29 March 2012 - 01:54 PM

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? =)

No, sorry. Actually, I've given up on this :oops: I hope someone will come up with a solution...

#535 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 29 March 2012 - 02:40 PM

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?

AutoIt         
; 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


#536 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 29 March 2012 - 05:09 PM

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, 29 March 2012 - 05:18 PM.

*GERMAN* Posted Image [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

#537 Mobius

Mobius

    Damaged by design

  • Active Members
  • PipPipPipPipPipPip
  • 724 posts

Posted 29 March 2012 - 06:55 PM

Here is a description of the required format: http://www.devsource.com/c/a/Architecture/Resources-From-PE-I/2/

Good link that filled in the blanks, thanks ProgAndy.
AutoIt3Camo Another Aut2Exe wrapper

Updated.


#538 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 29 March 2012 - 08:24 PM

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.

#539 Mobius

Mobius

    Damaged by design

  • Active Members
  • PipPipPipPipPipPip
  • 724 posts

Posted 29 March 2012 - 08:39 PM

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
AutoIt3Camo Another Aut2Exe wrapper

Updated.


#540 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 30 March 2012 - 07:19 AM

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, 30 March 2012 - 05:49 PM.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users