Leaderboard
Popular Content
Showing content with the highest reputation on 06/28/2014 in all areas
-
I have wrote a lot of binary code library for AutoIt before. I also discover many ways to generate binary code for AutoIt in the past. However, all of them have limitation or need some extra effort. Recently, I think I found the best and easiest way to generate the binary code. So I wrote this UDF, may be my last one about binary code. The Features:Both AutoIt x86 and x64 version are supported.Windows API and static variables can be use (code relocation supported).Decompression at run-time with smallest footprint LZMA decoder.Allocated memory blocks are released automatically.Most C source code works without modification.Two step or one step script generation, very easy to use.How It Works: The C source code must be compiled by MinGW GCC with "-S -masm=intel" option. Output is GAS syntax assembly file.BinaryCall Tool is able to convert the GAS syntax assembly file (*.s) to FASM syntax (*.asm). During the conversion, global symbols will be stored as "Symbol Jump Table" at the head of the file. The output file should be able to be assembled to binary file under command line by FASM.EXE. This syntax conversion is step 1.The step 2 is to assemble the file. BinaryCall Tool will use the embedded FASM to assemble every file twice to generate the relocation table. "BinaryCall.inc" will be included automatically before assembling to detect the Windows API and generate the "API Jump table". All the results will be compressed and converted to AutoIt script output.There are two major functions in the output script. _BinaryCall_Create() function allocates memorys, decompress the binary, relocates the address in memory, and fills the "API Jump Table"._BinaryCall_SymbolList() converts the "Symbol Jump Table" to memory addresses, and then store them as pointers in a DllStruct variable.Finally, we can use DllCallAddress() to call the memory address stored in the DllStruct.Step by Step Tutorial: Write C source code:#include <windows.h> void main() { MessageBox(0, "Hello", "Welcome Message", 1); }Use GCC MinGW 32/64 to compile the source code: gcc -S -masm=intel -m32 MessageBox.cUse BinaryCall Tool "GAS2AU3 Converter", select "MessageBox.s": If Not @AutoItX64 Then Local $Code = '...' Local $Reloc = '...' Local $Symbol[] = ["main"] Local $CodeBase = _BinaryCall_Create($Code, $Reloc) If @Error Then Exit Local $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) If @Error Then Exit EndIfPaste the output script, call the main() in AutoIt: #Include "BinaryCall.au3" ; Paste output here DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "main"))Try to run it! Change Log:v1.0Initial release.v1.1A lot of improvement for GAS2ASM converter and FASM header file.Add many C Run-Time library as inline asm subroutines.Add command-line to argc/argv parser for easy calling main() function.Add ability to redirect stdio.More C source code can work without modification in this version. Following open source projects are tested. And Yes, they can run as binary code library in AutoIt now. SQLite 3.8.5 TCC 0.9.26 PuTTY beta 0.63 v1.2Dynamic-link library (DLL) calling is supported now. If the C program requires a DLL file to run, just put it together with the source file. BinaryCall Tool will searches *.dll and exports all the symbols in these DLL files automatically. Of course, you need these DLL files when run the output script. However, it also works if you loaded them by last version of MemoryDll UDF.To add more Windows API library easily by editing the ini file.Better error handling and more error messages in output script.Add zero padding to avoid short jumps that crash the relocation table.BinaryCall Tool accepts drag and drop files now.Some small bug fixed. BinaryCall 1.0.zip BinaryCall 1.1.zip BinaryCall 1.2.zip3 points
-
Implementing Windows Explorer right pane
pixelsearch reacted to LarsJ for a topic
Note that this is a real Windows Explorer. But only the right pane. All functionality of Windows Explorer is working. E.g. keyboard shortcuts, the context (right click) menu, cut, copy, paste, drag & drop and automatic update of the window. Implementations There are three implementations: An implementation for Vista, 7 and 8, an implementation for Windows XP, and a SysListView32 based implementation for Vista, 7 and 8. The latter is named SysLv32.au3 in the examples. This is more or less the Windows XP implementation adapted for Vista, 7 and 8. Functionality The implementations are based on Shell interfaces. This means that most functionality of Windows Explorer is working automatically without any additional code. Other features: Position Explorer window in GUISpecify root and start foldersSpecify an initial icon view modeSpecify an icon view mode for the DesktopSpecify a file filter to filter files by extensionUse folder flags $FWF_NOBACKBROWSING, $FWF_SINGLESEL and $FWF_NOSUBFOLDERSBrowse to child/parent folder with Enter/Backspace keysDelete, disable and insert items in the context menuExecute context menu commands in codeDocumentation Use ExplorerWindowCreate() to create the right pane window. This function is located in Explorer\<Implementation>\WindowsExplorer.au3. You find documentation for the function in top of the file. Documentation for the Vista, 7, 8 implementation is included in the Examples section below. Ini file To handle Rename, New and View in the context menu, it's necessary to be able to identify these items. This seems only to be possible to do, by identifying the names. Because the names are localized, an ini file is used to store the names. Especially the View command depends on the ini file. If the View command isn't recognized, the icon view modes are not set properly. Rename and New commands are depending on the ini file, when the commands are selected with the keyboard. More information in the sections below. First release 2013-11-28 In first release Explorer right pane windows are created with enough functionality to get it to work. There are two implementations: One for Vista, 7 and 8, and one for Windows XP. First update 2014-03-14 This update consists primarily of bug fixes in first release. Because both APIConstants.au3 and WinAPIEx.au3 are included, the scripts can't run on AutoIt 3.3.10 without modifications. A new implementation for Vista, 7 and 8 is added. This implementation is based on a SysListView32 control. This is more or less the Windows XP implementation adapted for Vista, 7 and 8. Second update 2014-04-23 The implementations are based on Shell interfaces, and most functionality of Windows Explorer is working automatically. But you still have to integrate that functionality into your script. Especially you have to take care of keystrokes in combination with various controls and windows. E.g. the rename edit box, the context menu and dialog boxes. This update introduces an ini file: Explorer\Inifiles\ContextMenu.ini Third update 2014-05-02 The third update is mostly about the context menu. It's divided into two parts. The first part is about manipulating the context menu. The example shows how to delete, disable and add custom menu items. The second part shows how to execute context menu commands in code. The example implements Cut, Copy and Paste buttons. The spoiler section starts with an explanation of the message flow and message handlers. Final release 2014-05-10 Left, top, width and height parameters are added to the ExplorerWindowCreate() function. This makes it easier to position the Explorer window in the GUI. When the GUI is resized, the Explorer window is resized so that margins are retained. The margins can be used for buttons or other controls. The new parameters are implemented in the examples. Redundant code is moved from example files to common files. Some minor bug fixes. This is the final release of the small examples. It should not be too difficult to reuse the examples and code. I'm currently working on a large example where an address bar, a toolbar, a left pane and a status bar is implemented besides the right pane. This is a much bigger example, and it'll be more difficult to reuse the code. I'll probably add this example to a new thread. Final release, Vista update 2014-06-21 The Vista, 7, 8 example in first release dated 2013-11-28 was based on Vista code. The XP example was based on XP code. But most of the additional code in the next updates was XP code (see post 40). This meant that some functionality wasn't implemented completely under Vista and later. E.g. icon view modes. Examples The zip contains seven folders at the top level: 1. Basic example2. Position and size3. Navigation buttons4. Toolbar example5. Context menu6. Cut-copy-pasteExplorerThe first six folders are examples. The Explorer folder contains common files and includes. Resources specific for a particular example are contained in the example folder. There are three scripts for each example: Vista, 7, 8.au3, SysLv32.au3 and Windows XP.au3. Other examples (Vista and later) in posts below: Three examples where all panes are implemented (not just the right pane)You can find an example which implements the other panes in this post.This example shows how to merge all include files into a single Include folder.Implement proper tab order between LV and TV, and update LV on up/down keys in TV here.An example that shows how to cancel drag/drop operations can be found here. AutoIt 3.3.8 If you want to run the scripts on AutoIt 3.3.8 you need APIConstants.au3 and WinAPIEx.au3 by Yashied. The UDFs are not included in the zip. You must enable the UDFs in top of ShellFunctions.au3. The UDFs are already added, but commented out. And you must comment out the 3.3.10 UDFs in ShellFunctions.au3 and WERPFuncs.au3. Testet on XP 32 bit and Win 7 32/64 bit. The scripts can be run as both 32 and 64 bit programs. If you are running a 64 bit Windows you should run the scripts as 64 bit programs. Windows Explorer right pane.7z1 point -
Some of Jerome Herr's processing code samples in AutoIt
mesale0077 reacted to DatMCEyeBall for a topic
"Wavy Thing" #include <GDIPlus.au3> #include <Math.au3> ;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7 Opt("GUIOnEventMode", 1) Global Const $nPI = 3.1415926535897932384626433832795 Global Const $nTWOPI = $nPI * 2 Global $iNum = 25 Global $anPosX[$iNum] Global $nUnit, $nTheta, $nX, $nSzX, $nSzY Global $fClose = False Global $iW = 500, $iH = 300 Global $hGUI = GUICreate('"Wavy thing" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH) GUISetBkColor(0) GUISetOnEvent(-3, "_Exit") $nUnit = ($iW - 50) / $iNum _GDIPlus_Startup() Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt) Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFFCD300) Global $hPen = _GDIPlus_PenCreate(0xFF777777, 1) Global $hTimer = TimerInit() GUISetState() While Not $fClose If TimerDiff($hTimer) >= 33 Then $hTimer = TimerInit() _Draw() _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0) ConsoleWrite(TimerDiff($hTimer) & @CRLF) EndIf Sleep(33 - TimerDiff($hTimer) - 1) WEnd _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hCtxt) GUIDelete() Func _Draw() _GDIPlus_GraphicsClear($hGraphics, 0xBE000000) For $i = 0 To $iNum - 1 $nSzX = _Map(Sin($nTheta + ($nTWOPI / $iNum) * $i), -1, 1, 5, 10) $nSzY = _Map(Sin($nTheta + ($nPI / $iNum) * $i), -1, 1, 30, $iH / 1.2) $nX = _Map(Sin($nTheta + ($nPI / $iNum / 2) * $i), -1, 1, $i * $nUnit, $iW / 2) _GDIPlus_GraphicsFillDrawRect($hGraphics, $nX + 25, _CenterPoint($nSzY, $iH), $nSzX, $nSzY, $hBrush, $hPen) Next $nTheta += 0.0523 _ModIfGreater($nTheta, $nTWOPI) EndFunc ;==>_Draw Func _Exit() $fClose = True EndFunc ;==>_Exit Func _GDIPlus_GraphicsFillDrawRect($hGraphics, $nX, $nY, $nWidth, $nHeight, $hBrush = 0, $hPen = 0) _GDIPlus_GraphicsFillRect($hGraphics, $nX, $nY, $nWidth, $nHeight, $hBrush) _GDIPlus_GraphicsDrawRect($hGraphics, $nX, $nY, $nWidth, $nHeight, $hPen) Return 1 EndFunc ;==>_GDIPlus_GraphicsFillDrawRect Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2) Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1)) EndFunc ;==>_Map Func _ModIfGreater(ByRef $nVar, $nMod) $nVar = ($nVar > $nMod) ? (Mod($nVar, $nMod)) : ($nVar) EndFunc ;==>_ModIfGreater Func _CenterPoint($iCur, $iTotal) Return $iTotal / 2 - $iCur / 2 EndFunc ;==>_CenterPoint1 point -
Some of Jerome Herr's processing code samples in AutoIt
mesale0077 reacted to DatMCEyeBall for a topic
"Lava Lamp" #include <GDIPlus.au3> #include <Math.au3> ;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7 Opt("GUIOnEventMode", 1) Global Const $nPI = 3.1415926535897932384626433832795 Global Const $nTWOPI = $nPI * 2 Global $iNum = 125 Global $aiMaxSize[$iNum] Global $anOffset[$iNum] Global $nTheta, $nSz, $nX Global $aiPalette[] = [0x64F58F12, 0x640B9EE7, 0x644EA731, 0x64F4D910, 0x64F334E3] For $i = 0 To $iNum - 1 $aiMaxSize[$i] = Random(50, 120, 1) $anOffset[$i] = Random(0, $nTWOPI) Next Global $fClose = False Global $iW = 500, $iH = 500 Global $hGUI = GUICreate('"Lava Lamp" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH) GUISetOnEvent(-3, "_Exit") _GDIPlus_Startup() Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt) Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) Global $hBrush = _GDIPlus_BrushCreateSolid() Global $hTimer = TimerInit() GUISetState() While Not $fClose If TimerDiff($hTimer) >= 33 Then $hTimer = TimerInit() _Draw() _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0) ConsoleWrite(TimerDiff($hTimer) & @CRLF) EndIf Sleep(33 - TimerDiff($hTimer) - 1) WEnd _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hCtxt) GUIDelete() Func _Draw() _GDIPlus_GraphicsClear($hGraphics, 0xFF202020) For $i = 0 To $iNum - 1 _GDIPlus_BrushSetSolidColor($hBrush, $aiPalette[Mod($i, 5)]) $nX = _Map(Sin($nTheta + $anOffset[$i]), -1, 1, 150, 350 - $aiMaxSize[$i]) _GDIPlus_GraphicsFillRect($hGraphics, $nX, $iH / $iNum * $i, $aiMaxSize[$i], 20, $hBrush) Next $nTheta += 0.0523 / 2 _ModIfGreater($nTheta, $nTWOPI) EndFunc ;==>_Draw Func _Exit() $fClose = True EndFunc ;==>_Exit Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2) Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1)) EndFunc ;==>_Map Func _ModIfGreater(ByRef $nVar, $nMod) $nVar = ($nVar > $nMod) ? (Mod($nVar, $nMod)) : ($nVar) EndFunc ;==>_ModIfGreater1 point -
Some of Jerome Herr's processing code samples in AutoIt
mesale0077 reacted to DatMCEyeBall for a topic
"Trunk in space" #include <GDIPlus.au3> #include <Math.au3> ;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7 Opt("GUIOnEventMode", 1) Global Const $nPI = 3.1415926535897932384626433832795 Global Const $nTWOPI = $nPI * 2 Global $iSz = 300, $iNum = 40 Global $nTheta, $nAngle, $nRad = 200 Global $fClose = False Global $iW = 500, $iH = 500 Global $hGUI = GUICreate('"Trunk in space" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH) GUISetOnEvent(-3, "_Exit") _GDIPlus_Startup() Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt) Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) Global $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 6, 2) Global $hBrush = _GDIPlus_BrushCreateSolid() Global $hTimer = TimerInit() GUISetState() While Not $fClose If TimerDiff($hTimer) >= 33 Then $hTimer = TimerInit() _Draw() _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0) ConsoleWrite(TimerDiff($hTimer) & @CRLF) EndIf Sleep(33 - TimerDiff($hTimer) - 1) WEnd _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hCtxt) GUIDelete() Func _Draw() _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF) $nAngle = 0 Local $nX, $nY, $nS, $nScal Local $iF For $i = 0 To $iNum - 1 $nX = $iW / 2 - $nRad / 2 + Cos($nAngle) * $nRad $nY = $iH / 2.5 + Sin($nAngle) * $nRad $nS = _Map(Sin($nTheta + $nTWOPI / $iNum * $i * 2), -1, 1, 1, 0.7) $nScal = 1 - 0.03 * $i $iF = Int(255 / $iNum * $i) _GDIPlus_BrushSetSolidColor($hBrush, "0xFF" & Hex(_WinAPI_ColorHLSToRGB($iF, 100, 160), 6)) _GDIPlus_GraphicsFillDrawEllipse($hGraphics, 0, $nY, $iSz * $nScal * $nS, $iSz * $nScal * $nS, $hBrush, $hPen) $nAngle -= $nPI / $iNum Next $nTheta += 0.0523 _ModIfGreater($nTheta, $nTWOPI) EndFunc ;==>_Draw Func _GDIPlus_GraphicsFillDrawEllipse($hGraphics, $nX, $nY, $nWidth, $nHeight, $hBrush = 0, $hPen = 0) _GDIPlus_GraphicsFillEllipse($hGraphics, $nX, $nY, $nWidth, $nHeight, $hBrush) _GDIPlus_GraphicsDrawEllipse($hGraphics, $nX, $nY, $nWidth, $nHeight, $hPen) Return 1 EndFunc ;==>_GDIPlus_GraphicsFillDrawEllipse Func _Exit() $fClose = True EndFunc ;==>_Exit Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2) Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1)) EndFunc ;==>_Map Func _ModIfGreater(ByRef $nVar, $nMod) $nVar = ($nVar > $nMod) ? (Mod($nVar, $nMod)) : ($nVar) EndFunc ;==>_ModIfGreater1 point -
Nowhere in my post did I ask anyone to write it for me. I was asking a general question to ascertain which path I perhaps should be pursuing. An answer like, "it cannot be done" or "it takes an array" or some other words of enlightenment would have been appreciated. I do like to learn to do things for myself and I try to mitigate useless efforts especially when I have limited knowledge of a subject matter. So given the responses of limited usefulness, the thread is pretty much closed.1 point
-
BinaryCall UDF - Write Subroutines In C, Call In AutoIt
Ward reacted to DatMCEyeBall for a topic
This is a great tool for improving scripts that rely on complex equations. Thanks, I might use it over compiling a .dll in some cases1 point -
Stoex, How long would it be to write a script to test rather then asking someone else to do it for you? I bet it would be shorter than the time it takes to get an answer! M231 point
-
sanaldosya, If you use my ExtMsgBox UDF (the link is in my sig) you can continue the script while the dialog is displayed - or you could search for Yashied's NotifyBox UDF. M231 point
-
you can use /AutoIt3ExecuteLine ;some code Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"') ;other code1 point
-
MsgBox is a blocking function. Means it waits until the user presses a button or the display timeout has expired. What kind of information do you want to display? Is a user interaction needed?1 point
-
'?do=embed' frameborder='0' data-embedContent>>1 point
-
Function Name Lister 06/27/2014
mLipok reacted to jaberwacky for a topic
Updated OP to fix a bug as uncovered by mLipok, the master of finding bugs.1 point -
This UDF is not for dll. To use dll, you can build dll file and then use it by DllCall, or use MemoryDll UDF.1 point
-
I have an order...
yousefsamy reacted to JohnOne for a topic
There are 2. Try them, and pick your favourite. Don't remember their names, one might be ISN1 point -
As I said you in the >Printer UDF topic, your syntax was not correct Now, if you want to print into a file without being prompted for the file name, you can create your own local port (as a file) and use it with your printer when you install it. I just edit my UDF to add _AddLocalPrinterPort and _RemoveLocalPrinterPort, which will allow you to create a local "file" port : #Include "printers.au3" Local $sPrinterName = "My Dell 2335dn Printer" Local $sDriverName = "Dell 2335dn MFP" Local $sOutput = @TempDir & "\output.pcl" _AddPrinterDriver($sDriverName, "Windows x64", @ScriptDir & "\Printer\PCL\WINXP_VISTA_64\", @ScriptDir & "\Printer\PCL\WINXP_VISTA_64\sdf1m.INF") _AddLocalPrinterPort($sOutput) _AddPrinter($sPrinterName, $sDriverName, $sOutput) ; ... here you call you IE page for printing1 point
-
Some of Jerome Herr's processing code samples in AutoIt
DatMCEyeBall reacted to UEZ for a topic
I adapted the Wavy example to AutoIt: ;original java code by Jared "BlueThen" C. -> http://www.openprocessing.org/sketch/5671 ;converted to AutoIt by UEZ 2014 #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #pragma compile(UPX, False) #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Aut2Exe\Icons\AutoIt_Main_v10_48x48_RGB-A.ico") #pragma compile(inputboxres, False) #AutoIt3Wrapper_Run_After=upx.exe --best --lzma "%out%" #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Global $ghGDIPDll = $__g_hGDIPDll Global Const $iW = 500, $iH = 500, $sTitle = "GDI+ Wavy / FPS: " Global Const $hGUI = GUICreate($sTitle & "0", $iW, $iH) GUISetState() Global Const $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Global Const $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) _GDIPlus_BitmapDispose($hBmp) Global Const $hDC = _WinAPI_GetDC($hGUI) Global Const $hDC_Backbuffer = _WinAPI_CreateCompatibleDC($hDC) Global Const $DC_Obj = _WinAPI_SelectObject($hDC_Backbuffer, $hHBITMAP) Global Const $hGfxCtx = _GDIPlus_GraphicsCreateFromHDC($hDC_Backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hGfxCtx, 2) Global Const $hBrush = _GDIPlus_BrushCreateSolid(), $hBrushL = _GDIPlus_BrushCreateSolid(0xFF555555), $hBrushR = _GDIPlus_BrushCreateSolid(0xFFAAAAAA), $hPen = _GDIPlus_PenCreate(0xFF000000), $hPath = _GDIPlus_PathCreate() GUISetOnEvent($GUI_EVENT_Close, "_Exit") Global Const $halfw = $iW / 2, $halfh = $iH / 2, $iSquares = 14, $iSquareshalf = $iSquares / 2, $iHeight = 40, $iSize = 17, $iSizehalf = $iSize / 2, $iCount = 4 Global $x, $y, $z, $a = 9999998, $xm, $xt, $zm, $zt, $isox1, $isoy1, $isox2, $isoy2, $isox3, $isoy3, $isox4, $isoy4, $iColor, $iFPS = 0 Global $fSpeed = 0.1, $fPhase = 0.55, $fPerspective = 0.5, $fPower = 24 Global $tPoints = DllStructCreate("float coordinates[" & $iCount * 2 & "]") Global Const $ghGDI32Dll = DllOpen("gdi32.dll") AdlibRegister("ShowFPS", 1000) Do $a -= $fSpeed DllCall($__g_hGDIPDll, "int", "GdipGraphicsClear", "handle", $hGfxCtx, "dword", 0xF0101010) For $x = -$iSquareshalf To $iSquareshalf - 1 For $z = -$iSquareshalf To $iSquareshalf - 1 $y = ($fPower * Sin($fPhase * Sqrt((0 - $x) * (0 - $x) + (0 - $z) * (0 - $z)) + $a)) $xm = $x * $iSize - $iSizehalf $xt = $x * $iSize + $iSizehalf $zm = $z * $iSize - $iSizehalf $zt = $z * $iSize + $iSizehalf $isox1 = ($xm - $zm + $halfw) $isoy1 = (($xm + $zm) * $fPerspective + $halfh) $isox2 = ($xm - $zt + $halfw) $isoy2 = (($xm + $zt) * $fPerspective + $halfh) $isox3 = ($xt - $zt + $halfw) $isoy3 = (($xt + $zt) * $fPerspective + $halfh) $isox4 = ($xt - $zm + $halfw) $isoy4 = (($xt + $zm) * $fPerspective + $halfh) ;draw left side $tPoints.coordinates((1)) = $isox2 $tPoints.coordinates((2)) = $isoy2 - $y $tPoints.coordinates((3)) = $isox3 $tPoints.coordinates((4)) = $isoy3 - $y $tPoints.coordinates((5)) = $isox3 $tPoints.coordinates((6)) = $isoy3 + $iHeight $tPoints.coordinates((7)) = $isox2 $tPoints.coordinates((8)) = $isoy2 + $iHeight DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount) ;~ DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrushL, "handle", $hPath) ;draw right side $tPoints.coordinates((1)) = $isox3 $tPoints.coordinates((2)) = $isoy3 - $y $tPoints.coordinates((3)) = $isox4 $tPoints.coordinates((4)) = $isoy4 - $y $tPoints.coordinates((5)) = $isox4 $tPoints.coordinates((6)) = $isoy4 + $iHeight $tPoints.coordinates((7)) = $isox3 $tPoints.coordinates((8)) = $isoy3 + $iHeight DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount) ;~ DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrushR, "handle", $hPath) ;draw top rectangle $tPoints.coordinates((1)) = $isox1 $tPoints.coordinates((2)) = $isoy1 - $y $tPoints.coordinates((3)) = $isox2 $tPoints.coordinates((4)) = $isoy2 - $y $tPoints.coordinates((5)) = $isox3 $tPoints.coordinates((6)) = $isoy3 - $y $tPoints.coordinates((7)) = $isox4 $tPoints.coordinates((8)) = $isoy4 - $y $iColor = Int((4 + $y * 0.066666) * 48) $iColor = $iColor < 0x00 ? 0x00 : $iColor > 0xFF ? 0xFF : $iColor DllCall($__g_hGDIPDll, "int", "GdipSetSolidFillColor", "handle", $hBrush, "dword", 0xFF000000 + $iColor * 0x10000 + $iColor * 0x100 + $iColor) DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount) ;~ DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrush, "handle", $hPath) Next Next DllCall($ghGDI32Dll, "bool", "BitBlt", "ptr", $hDC, "int", 0, "int", 0, "int", $iW, "int", $iH, "ptr", $hDC_Backbuffer, "int", 0, "int", 0, "dword", $SRCCOPY) $iFPS += 1 Until False * Sleep(10) Func ShowFPS() WinSetTitle($hGUI, "", $sTitle & $iFPS) $iFPS = 0 EndFunc Func _Exit() AdlibUnRegister("ShowFPS") _GDIPlus_PathDispose($hPath) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrushL) _GDIPlus_BrushDispose($hBrushR) _GDIPlus_PenDispose($hPen) _WinAPI_SelectObject($hDC_Backbuffer, $DC_Obj) _GDIPlus_GraphicsDispose($hGfxCtx) _WinAPI_DeleteObject($hHBITMAP) _WinAPI_ReleaseDC($hGUI, $hDC) _GDIPlus_Shutdown() GUIDelete($hGUI) DllClose($ghGDI32Dll) Exit EndFunc Edit1: optimized the code a little bit - now slightly faster. Edit2: still some more optimizations which increases the fps speed Edit3: squeezed still a few fps Br, UEZ1 point -
TCPRecv and v3.3.12.0
DatMCEyeBall reacted to ripdad for a topic
Hi jpm, This entire issue is about the "-1 no byte received" error. There is nothing wrong when TCPRecv receives no bytes. (1) If no bytes have been received, it is usually because the remote server has not responded yet. This is not an error. The client is simply waiting on the server, which usually responds within a few seconds. (2) There are times during data transfer (for instance a file download of 1GB), that a server or somewhere in between, pauses for a moment and then resumes a few seconds later. This is not an error either. In a loop, while waiting for data during those few seconds at 10ms sleep, could result in hundreds of TCPRecv calls with no incoming data. In the course of downloading a 1GB file, it is Normal to have as many as 200 instances (or more) of "no byte received". This is not an error -- it's just the way things work on the internet. (3) In most cases, the First call of TCPRecv will be a blank string or no bytes received. So a script will fail with -1, when this happens. Even though, nothing is wrong. (4) In past versions, an error, any error, would normally cause a script to abort a TCPRecv operation. As it stands now, it would take two different error checks -- one to check for "-1 no byte received" and another for socket errors. Triggering an error because "no bytes have been received" is not needed. This is usually taken care of by the scripter when they check for valid incoming data. On the other hand, true socket errors like a closed connection, invalid socket or WSA errors, are very much needed. --- I understand that UDPRecv needed to be fixed. Surely, there must be a way to make TCPRecv behave the way it did in past versions (ie: v3.3.8.1), concerning no bytes received. As it stands now, most TCPRecv scripts on the forum are broken as of v3.3.10.0. That's including the examples in the help file. Coded the way they are, there is no way they could work properly. (ie: If @error Then Return False) They will fail with -1. If the function remains the same, I will treat the -1 as no error in my scripts. --- The .exe worked fine (under the conditions you set up for it). No crashes or abnormal problems. I only used the TCP functions - and transferred over 1GB of data while testing. Thanks for your time.1 point -
Since it is not likely to be implemented in the next AutoIt-releases, I have created some functions to work with nested DllStructs. It is merely proof of concept, proper error checking and documentation is missing. ; ----------------------------------------------------------------------------------------- ; Proof of concept: Implement nested DLLStructs using Arrays and normal DLLStructs ; Author: ProgAndy ; Nested Structs habe to be defined as Global Constants as TYPENAME or tagTYPENAME ; Access members via qualifier string: first_member.submember ; Array access with: member[2].submember[5] ; ; Access members via index: #2.#1.#6 ; Fetching Pointer for array element is possible: _DllStructGetPtr($struct, "array[3]") ; Member index and array index are 1-based. ; Supports STRUCT;...;ENDSCTRUCT of AutoIt-Beta + added naming structs and multiple nesting levels. ; The indexing is different: ; char a;STRUCT name;int b;ENDSTRUCT;int x ; Access-Qualifiers: a = #1 ; name.b = #2.#1 ; x = #3 ; ; _DllStructCreate accepts an optional 3rd parameter: a Scripting.Dictionary. ; This dictionary can contain your substructure definitions. (Key = TypeName, value = definition) ; ----------------------------------------------------------------------------------------- ; ### Nested DllStructs ####################################################################################### #region Nested DLLStructs Func _DLLStructCreate($sStruct, $pPtr = 0, $oSubStructs=0) ; Author: ProgAndy Local $sStructTag, $fClean=False If IsObj($oSubStructs) Then $fClean = True __DllStructExtractSubStructs($sStruct, $oSubStructs) Local $aDllStruct = __DLLStructParse($sStruct, $sStructTag, $oSubStructs) Local $err = @error If $fClean Then Local $a For $a In $oSubStructs.Keys If StringLeft($a, 27) = "A__XX__XX__UNNAMED_STRUCT__" Then $oSubStructs.Remove($a) Next EndIf If $err Then Return SetError(5, $err, 0) If @NumParams = 1 Or (@NumParams = 3 And $pPtr = 0) Then $aDllStruct[0][0] = DllStructCreate($sStructTag) Else $aDllStruct[0][0] = DllStructCreate($sStructTag, $pPtr) EndIf If @error Then Return SetError(@error, 0, 0) Return $aDllStruct EndFunc ;==>_DLLStructCreate Func _DllStructGetData(ByRef $aDllStruct, $sQualifier) ; Author: ProgAndy Local $sName = __DllStructFindIndex($aDllStruct, $sQualifier) If @error Then Return SetError(@error, 0, 0) Local $iIndex = @extended If IsArray($aDllStruct[$sName][0]) Then Local $aRet = $aDllStruct[$sName][0] $aRet[0][0] = DllStructCreate($aDllStruct[$sName][1], DllStructGetPtr($aDllStruct[0][0], $sName)) If $iIndex > 1 Then $aRet[0][0] = DllStructCreate($aDllStruct[$sName][1], DllStructGetPtr($aDllStruct[0][0], $sName) + DllStructGetSize($aRet[0][0]) * ($iIndex - 1)) If $sQualifier = '' Then Return $aRet Else Return _DllStructGetData($aRet, $sQualifier) EndIf Else If $iIndex = 0 Then Return DllStructGetData($aDllStruct[0][0], $sName) Return DllStructGetData($aDllStruct[0][0], $sName, $iIndex) EndIf EndFunc ;==>_DllStructGetData Func _DllStructGetPtr(ByRef $aDllStruct, $sQualifier="") ; Author: ProgAndy If @NumParams = 1 Then Return DllStructGetPtr($aDllStruct[0][0]) Local $sName = __DllStructFindIndex($aDllStruct, $sQualifier) If @error Then Return SetError(@error, 0, 0) Local $iIndex = @extended If IsArray($aDllStruct[$sName][0]) Then If $iIndex <= 1 And $sQualifier = "" Then Return DllStructGetPtr($aDllStruct[0][0], $sName) Else Local $tTemp = DllStructCreate($aDllStruct[$sName][1], 1) If $iIndex < 1 Then $iIndex = 1 Local $pPtr = DllStructGetPtr($aDllStruct[0][0], $sName) + ($iIndex - 1) * DllStructGetSize($tTemp) If $sQualifier = "" Then Return $pPtr $tTemp = DllStructCreate($aDllStruct[$sName][1], $pPtr) Local $aRet = $aDllStruct[$sName][0] $aRet[0][0] = $tTemp Return _DllStructGetPtr($aRet, $sQualifier) EndIf Else If $iIndex > 1 Then Return DllStructGetPtr($aDllStruct[0][0], $sName) + DllStructGetSize(DllStructCreate($aDllStruct[$sName][1], 1)) * ($iIndex-1) Return DllStructGetPtr($aDllStruct[0][0], $sName) EndIf EndFunc ;==>_DllStructGetPtr Func _DllStructGetSize(ByRef $aDllStruct) ; Author: ProgAndy Return DllStructGetSize($aDllStruct[0][0]) EndFunc Func _DllStructSetData(ByRef $aDllStruct, $sQualifier, $vValue) ; Author: ProgAndy Local $sName = __DllStructFindIndex($aDllStruct, $sQualifier) If @error Then Return SetError(@error, 0, 0) Local $iIndex = @extended If IsArray($aDllStruct[$sName][0]) Then Local $t = DllStructCreate($aDllStruct[$sName][1], DllStructGetPtr($aDllStruct[0][0], $sName)) If $iIndex > 1 Then $t = DllStructCreate($aDllStruct[$sName][1], DllStructGetPtr($aDllStruct[0][0], $sName) + DllStructGetSize($t) * ($iIndex - 1)) If $sQualifier = '' Then DllStructSetData(DllStructCreate("byte[" & DllStructGetSize($t) & "]", DllStructGetPtr($t)), 1, $vValue) Else Local $aRet = $aDllStruct[$sName][0] $aRet[0][0] = $t Return _DllStructSetData($aRet, $sQualifier, $vValue) EndIf Else If $iIndex = 0 Then Return DllStructSetData($aDllStruct[0][0], $sName, $vValue) Return DllStructSetData($aDllStruct[0][0], $sName, $vValue, $iIndex) EndIf EndFunc ;==>_DllStructSetData Func __DllStructFindIndex(ByRef $aDllStruct, ByRef $sQualifier) ; Author: ProgAndy Local $sName, $iIndex = 0 If IsInt($sQualifier) Then $sName = $sQualifier $sQualifier = "" Else $sName = __DllStructSplitNameIndexNext($sQualifier) $iIndex = @extended EndIf If IsInt($sName) Then Local $iBound = UBound($aDllStruct)-1 If $sName < 1 Or $sName > $iBound Then Return SetError(1, 0, 0) ; Find index, skipping alignment bytes For $i = 1 To $sName If IsInt($aDllStruct[$i][0]) Then $sName += 1 If $sName > $iBound Then Return SetError(1,0,0) Next Else $sName = __DllStructGetNameIndex($aDllStruct[0][1], $sName) If @error Then Return SetError(1, 0, 0) EndIf SetExtended($iIndex) Return $sName EndFunc Func __DllStructSplitNameIndexNext(ByRef $sName) ; Author: ProgAndy $sName = StringStripWS($sName, 8) Local $iPos = StringInStr($sName, ".", 1, 1), $aName If $iPos Then $aName = StringSplit(StringLeft($sName, $iPos - 1), '[]') $sName = StringTrimLeft($sName, $iPos) Else $aName = StringSplit(StringStripWS($sName, 8), '[]') $sName = "" EndIf If StringLeft($aName[1], 1) = "#" Then $aName[1] = Number(StringTrimLeft($aName[1], 1)) If $aName[0] = 1 Then Return SetExtended(0, $aName[1]) Return SetExtended($aName[2], $aName[1]) EndFunc ;==>__DllStructSplitNameIndexNext Func __DllStructGetNameIndex(ByRef $sData, $sName) ; Author: ProgAndy If $sName = "" Then Return SetError(2, 0, 0) Local $iPos = StringInStr($sData, ";" & StringLower($sName) & ";", 2, 1) If Not $iPos Then Return SetError(1, 0, 0) StringReplace(StringLeft($sData, $iPos), ";", ";", 0, 1) Return @extended EndFunc ;==>__DllStructGetNameIndex Func __DLLStructParse($sStruct, ByRef $sStructTag, $oSubStructs=0, $iAlignment=0) ; Author: ProgAndy Local Static $sTypes = "|align|BYTE|BOOLEAN|CHAR|WCHAR|short|USHORT|WORD|int|long|BOOL|UINT|ULONG|DWORD|INT64|UINT64|ptr|HWND|HANDLE|float|double|INT_PTR|LONG_PTR|LRESULT|LPARAM|UINT_PTR|ULONG_PTR|DWORD_PTR|WPARAM|" Local $a = StringSplit($sStruct, ";") Local $sName, $r = "", $sItems = ";", $aDllStruct[UBound($a)*2][2], $iMemberIndx = 0 $sStructTag = "" If StringStripWS($a[$a[0]], 8) = "" Then $a[0] -= 1 If $a[0] = 0 Then Return SetError(2, 0, 0) Local $iOffset = 0, $iFirstAlign = $iAlignment;, $iAlignment = 0 For $i = 1 To $a[0] $sName = StringRegExp($a[$i], "^\h*(\w+)\h*(\w*)\h*(?:\[(\d*)\])?\h*$", 1) If @error Then Return SetError(2, 0, 0) ReDim $sName[3] If $sName[0] = "" Then ; nothing ElseIf StringInStr($sTypes, '|' & $sName[0] & '|', 2, 1) Then $r &= $a[$i] & ";" If $sName[0] <> "align" Then $iMemberIndx += 1 $aDllStruct[$iMemberIndx][1] = $sName[0] $sItems &= $sName[1] & ";" If $sName[2] < 1 Then $sName[2] = 1 $iOffset += __DllStructAlignBytesType($iOffset, $sName[0], $iAlignment) & __DllStructGetTypeSize($sName[0])*$sName[2] Else $iAlignment = Number($sName[1]) If $i = 1 Then $iFirstAlign = $iAlignment EndIf Else $iMemberIndx += 1 Local $sSubTag, $sSubByteMember, $t $t = __DllStructSubCreate($sName[0], $sName[1], $sName[2], $sSubByteMember, $sSubTag, $oSubStructs, $iAlignment) If @error Then Return SetError(2, 0 , 0) Local $iAlign = __DllStructAlignBytesSubStruct($iOffset, $t, $iAlignment) If $iAlign Then $r &= "byte[" & $iAlign & "];" $aDllStruct[$iMemberIndx][0] = 1 ; mark alignment bytes $iMemberIndx += 1 $iOffset += $iAlign $sItems &= ";" EndIf $r &= $sSubByteMember $aDllStruct[$iMemberIndx][1] = $sSubTag $aDllStruct[$iMemberIndx][0] = $t $sItems &= $sName[1] & ";" $iOffset += DllStructGetSize(DllStructCreate($sSubTag, 1)) * $sName[2] EndIf Next ; $iOffset is length of struct, make sure size is correct for array of structs ;~ Local $iAlign = __DllStructAlignBytesSubStruct($iOffset, $aDllStruct, $iFirstAlign) Local $iAlign = __DllStructAlignBytesSubStruct($iOffset, $aDllStruct, $iAlignment) If $iAlign Then $r &= "byte[" & $iAlign & "];" $iOffset += $iAlign EndIf $aDllStruct[0][1] = $sItems ReDim $aDllStruct[$iMemberIndx + 1][2] $sStructTag = $r Return $aDllStruct EndFunc ;==>__DLLStructParse Func __DllStructSubCreate(ByRef $sType, ByRef $sName, ByRef $iCount, ByRef $sByteMember, ByRef $sStructTag, $oSubStructs = 0, $iAlignment = 0) ; Author: ProgAndy $sByteMember = "" Local $aDllStruct Select Case IsObj($oSubStructs) And $oSubStructs.Exists($sType) $aDllStruct = __DLLStructParse($oSubStructs($sType), $sStructTag, $oSubStructs, $iAlignment) If @error Then ContinueCase Case True $aDllStruct = __DLLStructParse(Eval("tag" & $sType), $sStructTag, $oSubStructs, $iAlignment) If @error Then ContinueCase Case Else $aDllStruct = __DLLStructParse(Eval($sType), $sStructTag, $oSubStructs, $iAlignment) If @error Then Return SetError(1, 0, 0) $sType = "tag" & $sType EndSelect Local $iSize = DllStructGetSize(DllStructCreate($sStructTag, 1)) If @error Or $iSize = 0 Then Return SetError(1, 0, 0) If Number($iCount) < 1 Then $iCount = 1 $sByteMember = "byte " & $sName & "[" & $iCount * $iSize & "];" Return $aDllStruct EndFunc ;==>__DllStructSubCreate Func __DllStructAlignBytesSubStruct($iOffset, ByRef $aDllStruct, $iAlignment = Default) Return __DllStructAlignBytesType($iOffset, __DllStructFindLargestMember($aDllStruct), $iAlignment) EndFunc Func __DllStructFindLargestMember(ByRef $aDllStruct) Local $iLargest = 0, $iNew ; find largest member alignment For $i = 1 To UBound($aDllStruct)-1 If IsArray($aDllStruct[$i][0]) Then $iNew = __DllStructFindLargestMember($aDllStruct[$i][0]) Else $iNew = __DllStructGetTypeSize($aDllStruct[$i][1]) EndIf If $iNew > $iLargest Then $iLargest = $iNew Next Return $iLargest EndFunc Func __DllStructAlignBytesType($iOffset, $sType, $iAlignment=Default) If IsInt($sType) Then Local $iLen = $sType Else Local $iLen = __DllStructGetTypeSize($sType) EndIf If IsKeyword($iAlignment) Or $iAlignment < 1 Then $iAlignment = 8 If $iLen = 1 Or $iAlignment = 1 Then Return 0 ElseIf $iAlignment > $iLen Then $iOffset = $iLen - Mod($iOffset, $iLen) If $iOffset = $iLen Then Return 0 Else $iOffset = $iAlignment - Mod($iOffset, $iAlignment) If $iOffset = $iAlignment Then Return 0 EndIf Return $iOffset EndFunc Func __DllStructGetTypeSize($sType) Local Static $iPtrSize = DllStructGetSize(DllStructCreate("ptr", 1)) Switch $sType Case "BYTE", "BOOLEAN", "CHAR" Return 1 Case "WCHAR", "short", "USHORT", "WORD" Return 2 Case "int", "long", "BOOL", "UINT", "ULONG", "DWORD", "float" Return 4 Case "INT64", "UINT64", "double" Return 8 Case "ptr", "HWND", "HANDLE", "INT_PTR", "LONG_PTR", "LRESULT", "LPARAM", "UINT_PTR", "ULONG_PTR", "DWORD_PTR", "WPARAM" Return $iPtrSize EndSwitch Return SetError(1,0,0) EndFunc Func __DllStructExtractSubStructs(ByRef $sStruct, ByRef $oSubStructs, $iStart = 0) ; ProgAndy Local Static $counter = 0 $sStruct = StringReplace(StringReplace(StringRegExpReplace($sStruct, "\s+", " "), "; ", ";", 0, 1), " ;", ";", 0, 1) $sStruct = StringReplace(";"&$sStruct&";", ";;", ";", 0, 1) If $iStart < 1 Then $iStart = StringInStr($sStruct, ";STRUCT", 2, 1) Local $iEnd, $iStart2, $iNameEnd, $sName While $iStart If Not IsObj($oSubStructs) Then $oSubStructs = ObjCreate("Scripting.Dictionary") $iNameEnd = StringInStr($sStruct, ";", 2, 1, $iStart+7) If Not $iNameEnd Then Return SetError(1, 0, 0) $sName = StringMid($sStruct, $iStart+7, $iNameEnd-$iStart-7) If $sName <> "" And Not StringRegExp($sName, "^\h\w+$") Then Return SetError(2,0,0) $iEnd = StringInStr($sStruct, ";ENDSTRUCT;", 2, 1, $iNameEnd) $iStart2 = StringInStr($sStruct, ";STRUCT", 2, 1, $iNameEnd) If $iStart2 > 0 And $iEnd > $iStart2 Then __DllStructExtractSubStructs($sStruct, $oSubStructs, $iStart2) Else Local $sTemp = StringLeft($sStruct, $iStart) Local $sSub = StringMid($sStruct, $iNameEnd+1, $iEnd - $iNameEnd - 1) Local $sTemp2 = StringTrimLeft($sStruct, $iEnd+9) __DllStructExtractSubStructs($sSub, $oSubStructs) Local $sAlign = "" Local $iAlign = StringInStr(";" & $sSub, ";align ", 2, -1) If $iAlign Then Local $iCut = StringInStr($sSub & ";", ";", 1, 1, $iAlign) $sAlign = ";" & StringMid($sSub, $iAlign, $iCut-$iAlign) EndIf $counter += 1 $oSubStructs("A__XX__XX__UNNAMED_STRUCT__" & $counter) = $sSub $sStruct = $sTemp & "A__XX__XX__UNNAMED_STRUCT__" & $counter & $sName & $sAlign & $sTemp2 EndIf $iStart = StringInStr($sStruct, ";STRUCT", $iStart) WEnd If @NumParams = 2 Then $sStruct = StringMid($sStruct, 2, StringLen($sStruct)-2) EndFunc #endregion Nested DLLStructs ; ### End Nested DllStructs ################################################################################### Some examples: Global Const $SUBTESTTYPE = "wchar s[12]" Global Const $tagTEST = "int test;int blub; SUBTESTTYPE hi[3]" $x = _DLLStructCreate("byte[2]; TEST x") _DllStructSetData($x, "x.blub", 23) MsgBox(0, 'x.blub = #2.#2', _DllStructGetData($x, "#2.#2")) MsgBox(0, 'Ptr to #1 and #1[2]', _DllStructGetPtr($x, "#1") & @CRLF & _DllStructGetPtr($x, "#1[2]")) _DllStructSetData($x, "x.hi[1].s", "hello") _DllStructSetData($x, "x.hi[3].s", "bb") _DllStructSetData($x, "x.hi[2].s", ":)") MsgBox(0, 'x.hi.s = x.hi[1].s', _DllStructGetData($x, "x.hi.s")) MsgBox(0, 'x.hi[2].s', _DllStructGetData($x, "x.hi[2].s")) MsgBox(0, 'x.hi[3].s', _DllStructGetData($x, "x.hi[3].s")) Edit: Alignment does not work correctly I'm not sure how to fix it yet. Edit: Implemented aligment calculation, including align keyword. Each nested structure has its own alignment, always calculated relative to structure beginning. I don't know if this is right. Edit: Alignment correction + some new features.1 point
-
arryo, You might find this a bit quicker if your file is very large: $file = FileOpen("test.txt", 0) $read = FileRead($file) If @error = -1 Then MsgBox(0, "Error", "File not read") Exit Else MsgBox(0, "Read", $read) If StringRegExp($read, "Markus") Then MsgBox(0, "Oops", "Match") Else MsgBox(0, "Oops", "No match") EndIf EndIf FileClose($file)Although it does not give you the position. M231 point
-
First, look the autoit help file... for the text file : $file = FileOpen("YOUR FILE", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in 1 character at a time until the EOF is reached While 1 $read = FileRead($file) If @error = -1 Then ExitLoop If StringInStr($read, "Markus") Then $position = StringInStr($read, "Markus") MsgBox(0,"",$position) EndIf Wend FileClose($file) But your file must to be small size with this method...1 point