• Similar Content

• Func _Binary(\$Int) ;Uncomment To Only Accept Integers #cs If IsInt(\$Int) = 0 Then Return 0 EndIf #ce If \$Int < 0 Then ;Negative Numbers Will Break The Function Return 0000 EndIf Local \$Integer = \$Int Dim \$Bin[1] = [Mod(\$Integer, 2)] Local \$Counter = 1 Do \$Integer = Floor(\$Integer / 2) _ArrayAdd(\$Bin, Mod(\$Integer, 2)) Until \$Integer = 0 _ArrayReverse(\$Bin) ;Reverses The Array Because As Is, The Product Is Backwards ;A Loop To Remove Any Preceding 0's or Add 0's To Keep At Least Four Digits Select Case \$Int <= 1 \$Integer = "00" & _ArrayToString(\$Bin, "") Case \$Int = 2 Or \$Int = 3 \$Integer = "0" & _ArrayToString(\$Bin, "") Case \$Int >= 8 \$Integer = StringTrimLeft(_ArrayToString(\$Bin, ""), 1) Case Else \$Integer = _ArrayToString(\$Bin, "") EndSelect ;You Can Comment It Out Without Anything Else Having A Problem Return \$Integer EndFunc I made this because I was writing something that I could use to play with Bitwise Operations and using Binary() by itself wasn't helping.
It's very basic and will only take positive integers because that's all I needed but I'm sure with a little tweaking you could make it fit with negative and float types.
It returns a string essentially but doesn't pose a problem when just changing numbers into binary digits.
Example: If you were to do _Binary(5) you would get "0101" and _Binary(8) would return "1000"
Between this last sentence and here I've changed this about a half dozen times to refine it a bit because without it checking if your number is < 0 it would break if a negative number was inserted and it wouldn't even have a problem if you put in Float Values, Regular or Special Characters but that negative value will do the trick lol.
Anyway, I hope someone finds some use of this and thank you for reading!
-Pick

• Hi AutoIt Programmers, i wanna figure out how to use Binary functions in C# like:

BinaryMid
BinaryLen
IsBinary and other basic ones were too ez, but those two were hard to noob like me.

• By Celtic88
hello !
just for fun
simple code to call dll api in new  thread ...
*update 21/02/2021
-add callback for return api call

• By Beege
Here is the latest assembly engine from Tomasz Grysztar, flat assembler g as a dll which I compiled using original fasm engine. He doesn't have it compiled in the download package but it was as easy as compiling a exe in autoit if you ever have to do it yourself. Just open up the file in the fasm editor and press F5.
You can read about what makes fasmg different from the original fasm HERE if you want . The minimum you should understand is that this engine is bare bones by itself not capable of very much. The macro engine is the major difference and it uses macros for basically everything now including implementing the x86 instructions and formats. All of these macros are located within the include folder and you should keep that in its original form.
Differences from previous dll function
I like the error reporting much better in this one. With the last one we had a ton error codes and a variable return structure depending on what kind of error it had. I even had an example showing you what kind of an error would give you correct line numbers vs wouldn't. With this one the stdout is passed to the dll function and it simply prints the line/details it had a problem with to the console. The return value is the number of errors counted.
It also handles its own memory needs automatically now . If the output region is not big enough it will virtualalloc a new one and virtualfree the previous.
Differences in Code
Earlier this year I showed some examples of how to use the macros to make writing assembly a little more familiar. Almost all the same functionality exists here but there are a couple syntax sugar items gone and slight change in other areas.
Whats gone is FIX and PTR. Both syntax sugar that dont really matter.
A couple changes to structures as well but these are for the better. One is unnamed elements are allowed now, but if it does not have a name, you are not allowed to initialize those elements during creation because they can only be intialized via syntax name:value . Previously when you initialized the elements, you would do by specifying values in a comma seperated list using the specific order like value1,value2,etc, but this had a problem because it expected commas even when the elements were just padding for alignment so this works out better having to specify the name and no need for _FasmFixInit function. "<" and ">" are not longer used in the initializes ether.
OLD: \$sTag = 'byte x;short y;char sNote[13];long odd[5];word w;dword p;char ext[3];word finish' _(_FasmAu3StructDef('AU3TEST', \$sTag));convert and add definition to source _(' tTest AU3TEST ' & _FasmFixInit('1,222,<"AutoItFASM",0>,<41,43,43,44,45>,6,7,"au3",12345', \$sTag));create and initalize New: \$sTag = 'byte x;short y;char sNote[13];long odd[5];word w;dword p;char ext[3];word finish' _(_fasmg_Au3StructDef('AU3TEST', \$sTag)) ;convert and add definition to source _(' tTest AU3TEST x:11,y:22,sNote:"AutoItFASM",odd:41,odd+4:42,odd+8:43,w:6,p:7,ext:"au3",finish:12345');create and initalize Extra Includes
I created a includeEx folder for the extra macros I wrote/found on the forums. Most of them are written by Thomaz so they may eventually end up in the standard library.
Edit: Theres only the one include folder now. All the default includes are in thier own folder within that folder and all the custom ones are top level.
Align.inc, Nop.inc, Listing.inc
The Align and Nop macros work together to align the next statement to whatever boundary you specified and it uses multibyte nop codes to fill in the space. Filling the space with nop is the default but you can also specify a fill value if you want. Align.assume is another macro part of align.inc that can be used to set tell the engine that a certain starting point is assumed to be at a certain boundary alignment and it will do its align calculations based on that value.
Listing is a macro great for seeing where and what opcodes are getting generated from each line of assembly code.  Below is an example of the source and output you would see printed to the console during the assembly. I picked this slightly longer example because it best shows use of align, nop, and then the use of listing to verify the align/nop code. Nop codes are instructions that do nothing and one use of them is to insert nop's as space fillers when you want a certian portion of your code to land on a specific boundary offset. I dont know all the best practices here with that (if you do please post!) but its a type of optimization for the cpu.  Because of its nature of doing nothing, I cant just run the code and confirm its correct because it didnt crash. I need to look at what opcodes the actual align statements made and listing made that easy.
source example:
procf and forcea macros
In my previous post I spoke about the force macro and why the need for it. I added two more macros (procf and forcea) that combine the two and also sets align.assume to the same function. As clarified in the previous post, you should only have to use these macros for the first procedure being defined (since nothing calls that procedure). And since its the first function, it should be the starting memory address which is a good place to initially set the align.assume address to.
Attached package should include everything needed and has all the previous examples I posted updated. Let me know if I missed something or you have any issues running the examples and thanks for looking

Update 04/19/2020:
A couple new macros added. I also got rid of the IncludeEx folder and just made one include folder that has the default include folder within it and all others top level.
dllstruct macro does the same thing as _fasmg_Au3StructDef(). You can use either one; they both use the macro.
getmempos macro does the delta trick I showed below using anonymous labels.
stdcallw and invokew macros will push any parameters that are raw (quoted) strings as wide characters
Ifex include file gives .if .ifelse .while .until  the ability to use stdcall/invoke/etc inline. So if you had a function called "_add" you could do .if stdcall(_add,5,5) = 10. All this basically does in the background is perform the stdcall and then replaces the comparison with eax and passes it on to the original default macros, but is super helpful for cleaning up code and took a ton of time learning the macro language to get in place.

Update 05/19/2020:
Added fastcallw that does same as stdcallw only
Corrected missing include file include\macro\if.inc within win64au3.inc
fasmg 5-19-2020.zip

Previous versions:

• By Beege
Here is an old goodie from ms demonstrating concepts behind multithreading and using mutexes to control sharing the screen. Its unfortunately just a console application so you have to press compile (f7) to run (can get annoying if you want to play with the code) but still pretty cool :). Each little question mark box (could be any character (used to be a smiley face in win 7)) is its own thread keeping track of its own coordinates. Each thread shares the screenmutex by kinda waiting in line for ownership of it. When the thread gains control it updates the screen, then releases the mutex for the next thread.

First I wrote it in pure autoit to confirm all working as expected. The Console functions actually threw me for a loop. They actual want the whole value of the coord structs and not a ptr to it so that "struct" without a * was a little uncommon. Below au3 code is just the lonely cell bouncing around.
Func _BounceAU3() ;set a random starting id. we use this to rotate the colors Local \$iMyID = Random(1, 15, 1) Local \$tMyCell = DllStructCreate('char mc'), \$tOldCell = DllStructCreate('char oc') Local \$tMyAttrib = DllStructCreate('word ma'), \$tOldAttrib = DllStructCreate('word oa') Local \$tCoords = DllStructCreate(\$tagCOORD), \$tOld = DllStructCreate(\$tagCOORD) Local \$tDelta = DllStructCreate(\$tagCOORD) ;Random start and delta values \$tCoords.X = Random(0, 119, 1) \$tCoords.Y = Random(0, 29, 1) \$tDelta.X = Random(-3, 3, 1) \$tDelta.Y = Random(-3, 3, 1) ;set character/cell attributes \$tMyCell.mc = \$iMyID > 16 ? 0x01 : 0x02 ; doesnt seem to make a differnce in windows 10 \$tMyAttrib.ma = BitAND(\$iMyID, 0x0F) ; Set the character color Do ;check the last position values DllCall('kernel32.dll', "bool", "ReadConsoleOutputCharacter", "handle", \$g_hStdHandle, "struct*", \$tOldCell, "dword", 1, "struct", \$tOld, "dword*", 0) DllCall('kernel32.dll', "bool", "ReadConsoleOutputAttribute", "handle", \$g_hStdHandle, "struct*", \$tOldAttrib, "dword", 1, "struct", \$tOld, "dword*", 0) ;if the last postion was this cell, blank/empty the cell. (Otherwise its been taken over by another thread) If (\$tOldCell.oc = \$tMyCell.mc) And (\$tOldAttrib.oa = \$tMyAttrib.ma) Then DllCall('kernel32.dll', "bool", "WriteConsoleOutputCharacter", "handle", \$g_hStdHandle, "byte*", 0x20, "dword", 1, "struct", \$tOld, "dword*", 0) EndIf ;write the current cell DllCall('kernel32.dll', "bool", "WriteConsoleOutputCharacter", "handle", \$g_hStdHandle, "struct*", \$tMyCell, "dword", 1, "struct", \$tCoords, "dword*", 0) DllCall('kernel32.dll', "bool", "WriteConsoleOutputAttribute", "handle", \$g_hStdHandle, "struct*", \$tMyAttrib, "dword", 1, "struct", \$tCoords, "dword*", 0) ;update coords \$tOld.X = \$tCoords.X \$tOld.Y = \$tCoords.Y \$tCoords.X += \$tDelta.X \$tCoords.Y += \$tDelta.Y ;change directions if we are out of bounds If \$tCoords.X < 0 Or \$tCoords.X >= 120 Then \$tDelta.X *= -1 If \$tCoords.Y < 0 Or \$tCoords.Y >= 30 Then \$tDelta.Y *= -1 Sleep(75) Until GUIGetMsg() = -3 EndFunc ;==>_BounceAU3
From there the that function converted into assembly so we can call as a thread. The only real differences are the extra parameters we passing as a structure and I also generate the random starting values in autoit instead, then pass them to the function. Here is what the main assembly function looks like. I added comments for each peice of code from au3 that we are translating: