Leaderboard
Popular Content
Showing content with the highest reputation on 05/22/2020 in all areas
-
You could also work without _ArraySearch. #include <Array.au3> Global $sSearch, $iCount = 0 Global $aTestArr[6]= ["1--2--3--4", _ "3--3--1--6", _ "1--2--3--44", _ "77--12--3--6", _ "1--2--3--4", _ "3--9--3--4"] _ArrayDisplay($aTestArr) $sSearch = "1--2--3--4" For $i = 0 To UBound($aTestArr) - 1 If $aTestArr[$i] == $sSearch Then ConsoleWrite("+ Index = " & $i & " Searchstring found !" & @CRLF) $iCount += 1 EndIf Next ConsoleWrite("< >>>> " & $sSearch & " was found " & $iCount & " time(s)" & @CRLF & @CRLF)2 points
-
Custom Registry Functions UDF
seadoggie01 and one other reacted to Mbee for a topic
Thank you enormously, @argumentum, for the kind words! You have no idea how long it's been since I've received such a thoughtful and positive assessment of something I've created. You've not only made my day, you've made my month! 😊 As for your fondness for sharing and suggestion that I should consider doing likewise, I'll push myself to engage more. It's almost always pleasurable. In fact, I'm going to post a new UDF within a few days that is, my own opinion, vastly more rational than the remarkably weird "_PathSplit()" function. I stopped using the built-in function a very, very long time ago and replaced with the UDF in question because I just couldn't stand the illogical returns from PathSplit(). But every once in a while, some unusual path string would result in something unexpected, so I knew it wasn't quite there yet. By pure coincidence, I finally tracked down and squashed that that bug flat this very night! Here are some examples of how it's different... I don't bother returning an array, which I always thought was kinda silly, since you always just end up assigning a var like $sFileName to the appropriate array element, so I cut out the middleman and returned the various split path elements as ByRef variables. And totally unlike the built-in function, when you call mine you never need to do any further string wrangling, for example ensuring that the drive string ALWAYS has a colon and backslash. And that the end of the folder name NEVER has a terminating backslash, so you don't have to test for that. After the call, you can always simply concatenate the returned elements and produce a syntactically valid path. i.e.... $sFolderPath = $sDrive & $sFolderName $sFilename = $sFilename & $sExtensionWithDot You could NEVER count on that using the built-in function. A special feature is the ability to specify that you want my function to try to disambiguate ambiguous paths. For example, the string 'Howdy' is a syntactically valid path, but what does it represent? It could be a folder name, or a file name without an extension, or something else. If you tell me to, I'll try to determine which was meant. Anyway, I just want to go through and ensure that the documentation is correct and comprehensible. Once that's done, I'll post it. Finally, I'm afraid that I'm not at all sure at all that my General Registry UDF doesn't need more testing. In fact, I'm sure it does. If you want to create a test script and munch though a bunch of different operations with different key lengths, I would be greatly in your debt. If not, I'll see what I can put together... Good night and thanks again, gracious sir!2 points -
Custom Registry Functions UDF
seadoggie01 and one other reacted to argumentum for a topic
Got the UDF. Nice looking code. Looking back, it makes my coding look ugly Still no test.au3 in the package but by now, you know the code is good. No need for testing. As far as getting ... "diminishing wording" from users in the forum, I personally prefer peer reviewing over keeping to my self. I find sharing enlightening, either for me or for the next one looking at the same circumstance. Therefore is better to share than not. I recently rewrote code I submitted as a ticket, because I myself, could not make sense of what I've posted. And that is just one example of my "limitations". I too am getting older. We all are. So what. The one thing I've learned is to be kind, even to the unkind. In any case, what I posted above was all in good fun. And am glad you shared the code. Cheers2 points -
@Mbee Just in case you were wondering if there was a way to get a list of files that were copied to the clipboard (not copy path), the example below shows how it can be done. It could easily be modified to work with either a text list (like files/folders copied as paths) or actual files/folders that were copied. #include <Constants.au3> #include <Clipboard.au3> #include <Array.au3> #include <WinAPISysWin.au3> #include <WinAPIMisc.au3> #cs Below is an example of how to display a list of files/folders that were copied to the clipboard, not "copy path" but actually highlighted and copied. One benefit of doing it this way is that you can confirm that there is a file list in the clipboard before proceeding. $CF_HDROP will only be available when there is a list of files in the clipboard. #ce display_copied_file_list() Func display_copied_file_list() Const $tagDROPFILES = _ "struct;" & _ "dword offset;" & _ $tagPoint & ";" & _ "boolean fNC;" & _ "boolean fWide;" & _ "endstruct;" Local $tByteBuffer = "", $tDropFiles = "", $tFileArray = "" Local $iFileArrayLength = 0 ;If clipboard does not contain a list of copied files, then exit with msg If Not _ClipBoard_IsFormatAvailable ($CF_HDROP) Then Exit MsgBox($MB_ICONERROR, "ERROR", "No files in clipboard") ;Get file list data from clipboard (data is binary) $xData = _ClipBoard_GetData($CF_HDROP) ;Create a byte buffer structure to hold the data and copy the data to it $tByteBuffer = DllStructCreate(StringFormat("byte data[%i]", BinaryLen($xData))) $tByteBuffer.data = $xData ;Create a DROPFILES structure to access clipboard data $tDropFiles = DllStructCreate($tagDROPFILES, DllStructGetPtr($tByteBuffer)) ;Create a file list array structure to access the file list array $iFileArrayLength = BinaryLen($xData) - DllStructGetSize($tDROPFILES) $tFileArray = DllStructCreate(StringFormat("byte data[%i]", $iFileArrayLength), _ DllStructGetPtr($tDropFiles) + $tDropFiles.offset) ;Convert file list array struct to an array and display it $aFiles = _WinAPI_StructToArray($tFileArray) _ArrayDisplay($aFiles, "List of files copied to clipboard") EndFunc2 points
-
AutoIt v3.3.15.3 Beta View File 3.3.15.3 (16th May, 2020) (Beta) AutoIt: - Added #3681: Lang Variable prefix "o". - Fixed #2915: Map memory leak. - Fixed: Map errors with index < 0. UDFs: - Changed #3620: Removed "stable" from _ArraySort function header. - Added #3670: DriveGetDrive() @error doc clarification. - Added #3574: GuiCtrlCreateInput() Doc $ES_AUTOHSCROLL precision. - Fixed: Problem with _WinAPI_GetFontResourceInfo & _WinAPI_GetFontMemoryResourceInfo - Fixed #3728: Added optional parameter to force single column 2D array to 1D. - Fixed #3678: Amended Help file to show that function with no text blanks a line, not removes it. - Fixed #3757: Added note to GUICtrlListView_SetColor* pages about need to use BGR format. - Fixed #3697: _WinAPI_GetOverlappedResult() failure. Submitter Jon Submitted 05/16/2020 Category Beta1 point
-
1 point
-
@CYCho It looks like you've gone one level too deep with shadowroots. Try this modified version -- #include "wd_core.au3" #include "wd_helper.au3" _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path=chrome.log') Local $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"goog:chromeOptions": {"w3c": true}}}}' _WD_Startup() Local $sSession = _WD_CreateSession($sDesiredCapabilities) Sleep(50) _WD_ConsoleVisible(False) _WD_Navigate($sSession, "chrome://settings/help") Local $oSettingsUISR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByTagName, "settings-ui") Local $oTemp = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "#container", $oSettingsUISR) Local $oSettingsMainSR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByCSSSelector, "#main", $oTemp) Local $oSettingsAboutPageSR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByCSSSelector, "settings-about-page", $oSettingsMainSR) Local $oChromeStatusDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "#updateStatusMessage", $oSettingsAboutPageSR) _WD_HighlightElement($sSession, $oChromeStatusDiv, 1) Here's another alternative for obtaining the same result (replaces code after _WD_Navigate) -- $sJavascript = 'return document.querySelector("body > settings-ui").shadowRoot.querySelector("#main").shadowRoot.querySelector("settings-about-page").shadowRoot.querySelector("#updateStatusMessage")' Local $STemp = _WD_ExecuteScript($sSession, $sJavascript) Local $oJson = Json_Decode($STemp) Local $oChromeStatusDiv = Json_Get($oJson, "[value][" & $_WD_ELEMENT_ID & "]") _WD_HighlightElement($sSession, $oChromeStatusDiv, 1)1 point
-
If you have problems with uploading larger files, you need to increase http timeouts. Change VT_Open() function to this: ; #FUNCTION# ============================================================================================= ; Name...........: VT_Open ; Description ...: Initialize and get session handle & connection handle ; Syntax.........: VT_Open() ; guinness ; #FUNCTION# ============================================================================================= Func VT_Open() Local $aAPI[2] = [0, 0] $aAPI[$eAPI_HttpOpen] = _WinHttpOpen() If @error Then $aAPI[$eAPI_HttpOpen] = -1 _WinHttpSetTimeouts($aAPI[$eAPI_HttpOpen], 9900, 60000, 31000, 90000) $aAPI[$eAPI_HttpConnect] = _WinHttpConnect($aAPI[$eAPI_HttpOpen], $__sVirusTotal_Page) If @error Then $aAPI[$eAPI_HttpConnect] = -1 Return $aAPI EndFunc ;==>VT_Open1 point
-
WebDriver UDF - Help & Support (II)
Danp2 reacted to JLogan3o13 for a topic
@HJL and @Danp2 I am fine with it continuing with general webdriver questions so long as Danp2 is comfortable still helping. I think answering questions around how to register so many passwords on a website, however, is not something we want to support. Even if you do not have malicious intent, HJL, it doesn't mean that someone else could not come along and use such code for less than upstanding purposes.1 point -
Is there a non-brute force way to separate files on clipboard?
FrancescoDiMuro reacted to mikell for a topic
The very first time I provide help so easily. Glad I could do so !1 point -
Custom Registry Functions UDF
seadoggie01 reacted to Mbee for a topic
I am so damn sorry! Seriously - no sarcasm. I had finished alpha coding shortly after I posted my request, but my logic was too complex for me to follow with sufficient care to believe I could actually do what I claimed to be able to do. I'm an old man whose intellect certainly isn't anywhere what it once was, and I was too anxious about getting mocked -- however gently -- for submitting crap to submit my code. But I really do feel awful for not letting you know what was going on. And I also apologize for not checking in at the forum until now to see your notification. Anyway, I've now attached what I have. Of course you can take all the time you wish to examine it. Thanks UniversalRegAccessUDF_v0.3a.zip1 point -
1 point
-
OutlookEX UDF - Help & Support (IV)
sungmin0206 reacted to water for a topic
Here is a first example tested with the EML-files you provided: <snip> The code has been moved to the OutlookEX example scripts thread (link can be found in my signature.1 point -
OutlookEX UDF - Help & Support (IV)
sungmin0206 reacted to water for a topic
Will do my very best and post my results here1 point -
The collection of examples in .NET Common Language Runtime (CLR) Framework shows that there are virtually no limits to the possibilities that the usage of .NET Framework and .NET code in AutoIt opens up for. One possibility which certainly is very interesting is the possibility of using C# and VB code in AutoIt. That is, to create, compile and execute C# and VB source code directly through an AutoIt script without the need for any external tools at all, eg. an integrated development environment (IDE) program or similar. You can even create a .NET assembly dll-file with your C# or VB code that you can simply load and execute. Why is it interesting to execute C# or VB code in an AutoIt script? It's interesting because C# and VB code is executed as compiled code and not as interpreted code like AutoIt code. Compiled code is very fast compared to interpreted code. In AutoIt and all other interpreted languages probably 99% or more of the total execution time is spend by the code interpretor to interpret the code lines, while only 1% or less of the total execution time is spend by executing the actual code. Compiled code is directly executable without the need for a code interpretor. That's the reason why compiled code is so much faster than interpreted code. Using C# and VB code in AutoIt is interesting because it can be used to performance optimize the AutoIt code. There may be many other good reasons for using C# and VB code in AutoIt, but here the focus is on code optimization. In the help and support forums you can regularly find questions related to this topic. You can find many examples where assembler code is used in connection with performance optimization. Recently, there has been some interest in FreeBASIC. Code optimization is clearly a topic that has some interest. How difficult is writing C# and VB code compared to assembler and FreeBASIC code? It's certainly much easier and faster than writing assembler code. Because you can do everything through AutoIt without the need for an IDE, it's probably also easier than FreeBASIC. As usually you get nothing for free. The cost is that there is some overhead associated with executing compiled code. You must load and start the code. You need methods to move data back and forth between the AutoIt code and the compiled code. You'll not see that all compiled code is 100 times faster than AutoIt code. Somewhere between 10 and 100 times faster is realistic depending on the complexity of the code. And probably also only code running in loops is interesting and preferably a lot of loops. How C# and VB code can be used in AutoIt through .NET Framework is what this example is about. The rest of first post is a review of introductory C# and VB examples. The purpose of the examples is to make it easier to use C# and VB code in AutoIt. They show how to do some of the basic things in C#/VB that you can do in AutoIt. They focus on topics that are relevant when both AutoIt and C#/VB code is involved. Eg. how to pass variables or arrays back and forth between AutoIt and C#/VB code. The examples are not meant to be a regular C#/VB tutorial. C# and VB Guides in Microsoft .NET Documentation is a good place to find information about C# and VB code. Dot Net Perls example pages have some nice examples. To avoid first post being too long, three posts are reserved for topics that will be presented in the coming weeks. DotNet.au3 UDF DotNet.au3 UDF to access .NET Framework from AutoIt is used to access the .NET Framework. But you do not at all need a detailed knowledge of the code in DotNet.au3 to use C#/VB code in AutoIt. The UDF is stored as DotNetAll.au3 in Includes\ in the zip-file in bottom of post. Includes\ only contains this file. Introductory C# and VB examples The code in the examples below is VB code. But the zip-file in bottom of post contains both C# and VB versions of the examples. Code templates This is the vb and au3 code templates that's used in all of the examples. TemplateVB.vb (TemplateVB-a.vb is provided with comments): Imports System Class Au3Class Public Sub MyMethod() Console.WriteLine( "Hello world from VB!" ) End Sub End Class Note that Console.WriteLine writes output to SciTE console. TemplateVB.au3: #include "..\..\..\Includes\DotNetAll.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() Local $oNetCode = DotNet_LoadVBcode( FileRead( "TemplateVB.vb" ), "System.dll" ) Local $oAu3Class = DotNet_CreateObject( $oNetCode, "Au3Class" ) $oAu3Class.MyMethod() EndFunc Usually, 2 code lines are sufficient to make .NET code available in AutoIt. DotNet_LoadVBcode() compiles the VB code, creates the .NET code in memory, loads the code into the default domain and returns a .NET code object which is a reference to the .NET code. DotNet_CreateObject() takes the .NET code object and a class name as input parameters and creates an object from the class. See DotNet.au3 UDF. Now the sub procedure MyMethod in the VB code can be executed as an object method. Most examples contains just a few code lines like the templates. I don't want to review all examples, but to get an idea of what this is about, here's a list of the top level folders in the zip-file: Code templates Introductory topics Comments Comment block Line continuation ConsoleWrite MessageBox Public keyword Multiple methods Subs, functions Global variable Error handling Missing DLL-file Imports, using CS-VB mismatch Code typing errors Set @error macro Passing variables Passing 1D arrays Passing 2D arrays Simple examples Prime numbers Create DLL Prime numbers So far, there is only one example with more than just a few code lines. This is an example of calculating prime numbers. This example is also used to show how to create a .NET assembly dll-file. These two examples are reviewed with more details below. Prime numbers The example calculates a certain number of prime numbers and returns the prime numbers as a 1D array. It shows how to pass an AutoIt variable (number of prime numbers) to the C#/VB code and how to return a 1D array of integers (the prime numbers) from the C#/VB code to AutoIt. Especially arrays are interesting in relation to compiled code. This is Microsoft documentation for VB arrays and C# arrays. Design considerations If you want to create a UDF that uses advanced techniques such as compiled code, and you want to make it available to other members, you should consider the design. Consider how the code should be designed to be attractive to other members. You should probably not design the code so other members will need to execute .NET code, create objects, and call object methods in their own code. This should be done in a function in the UDF so that a user can simply call an easy-to-use AutoIt function in the usual way. AutoIt and VB code There are three versions of the example. A pure AutoIt version in the au3-folder, an AutoIt/VB version in the VB-folder and an AutoIt/C# version in the CS-folder. The pure AutoIt and the AutoIt/VB versions are reviewed below. AutoIt code in au3\CalcPrimes.au3. This is the pure AutoIt UDF to calculate primes: #include-once Func CalcPrimes( $nPrimes ) Local $aPrimes[$nPrimes], $iPrime = 2, $iPrimes = 0 If $nPrimes <= 100 Then ConsoleWrite( $iPrime & @CRLF ) ; Store first prime $aPrimes[$iPrimes] = $iPrime $iPrimes += 1 $iPrime += 1 ; Loop to calculate primes While $iPrimes < $nPrimes For $i = 0 To $iPrimes - 1 If Mod( $iPrime, $aPrimes[$i] ) = 0 Then ExitLoop Next If $i = $iPrimes Then If $nPrimes <= 100 Then ConsoleWrite( $iPrime & @CRLF ) $aPrimes[$iPrimes] = $iPrime $iPrimes += 1 EndIf $iPrime += 1 WEnd Return $aPrimes EndFunc Note the similarity between the AutoIt code above and the VB code below. If you can write the AutoIt code you can also write the VB code. VB code in VB\CalcPrimesVB.vb to calculate primes: Imports System Class PrimesClass Public Function CalcPrimes( nPrimes As Integer ) As Integer() Dim aPrimes(nPrimes-1) As Integer, iPrime As Integer = 2, iPrimes As Integer = 0, i As Integer If nPrimes <= 100 Then Console.WriteLine( iPrime ) 'Store first prime aPrimes(iPrimes) = iPrime iPrimes += 1 iPrime += 1 'Loop to calculate primes While iPrimes < nPrimes For i = 0 To iPrimes - 1 If iPrime Mod aPrimes(i) = 0 Then Exit For Next If i = iPrimes Then If nPrimes <= 100 Then Console.WriteLine( iPrime ) aPrimes(iPrimes) = iPrime iPrimes += 1 End If iPrime += 1 End While Return aPrimes End Function End Class AutoIt code in VB\CalcPrimesVB.au3. This is the AutoIt/VB UDF to calculate primes. #include-once #include "..\..\..\..\..\Includes\DotNetAll.au3" Func CalcPrimesVBInit() CalcPrimesVB( 0 ) EndFunc Func CalcPrimesVB( $nPrimes ) Static $oNetCode = 0, $oPrimesClass = 0 If $nPrimes = 0 Or $oNetCode = 0 Then ; Compile and load VB code, create PrimesClass object $oNetCode = DotNet_LoadVBcode( FileRead( "CalcPrimesVB.vb" ), "System.dll" ) $oPrimesClass = DotNet_CreateObject( $oNetCode, "PrimesClass" ) If $nPrimes = 0 Then Return EndIf ; Execute CalcPrimes method and return 1D array of primes Return $oPrimesClass.CalcPrimes( $nPrimes ) EndFunc Note the initialization code in CalcPrimesVB() where the VB code is compiled and loaded and the $oPrimesClass object is created. If the user forgets to call CalcPrimesVBInit() it'll work anyway. Examples with pure AutoIt code in au3\Examples.au3. This is user code: #include <Array.au3> #include "CalcPrimes.au3" Opt( "MustDeclareVars", 1 ) Examples() Func Examples() ShowPrimes( 10 ) ; Used under development ShowPrimes( 1000 ) ; 400 milliseconds ShowPrimes( 5000 ) ; 8 seconds EndFunc Func ShowPrimes( $nPrimes ) ConsoleWrite( "$nPrimes = " & _ $nPrimes & @CRLF ) Local $hTimer = TimerInit() Local $aPrimes = CalcPrimes( $nPrimes ) ConsoleWrite( "Time = " & _ TimerDiff( $hTimer ) & @CRLF & @CRLF ) _ArrayDisplay( $aPrimes ) EndFunc Note again that the user code in the pure AutoIt examples above is almost identical to the user code in the AutoIt/VB examples below. The only difference the user will notice is the speed. To calculate 5000 prime numbers, the C#/VB code is 100 times faster. Try yourself. Examples with AutoIt/VB code in VB\ExamplesVB.au3. This is user code: #include <Array.au3> #include "CalcPrimesVB.au3" Opt( "MustDeclareVars", 1 ) ExamplesVB() Func ExamplesVB() CalcPrimesVBInit() ShowPrimesVB( 10 ) ; Used under development ShowPrimesVB( 1000 ) ; 10 milliseconds ShowPrimesVB( 5000 ) ; 80 milliseconds ShowPrimesVB( 10000 ) ; 200 milliseconds ;ShowPrimesVB( 50000 ) ; 5 seconds EndFunc Func ShowPrimesVB( $nPrimes ) ConsoleWrite( "$nPrimes = " & _ $nPrimes & @CRLF ) Local $hTimer = TimerInit() Local $aPrimes = CalcPrimesVB( $nPrimes ) ConsoleWrite( "Time = " & _ TimerDiff( $hTimer ) & @CRLF & @CRLF ) _ArrayDisplay( $aPrimes ) EndFunc .NET assembly dll-file In a production environment the compiled VB code should be stored in a .NET assembly dll-file. The first step is to create the dll-file from the VB source code: #include "..\..\..\..\..\Includes\DotNetAll.au3" ; Compile VB code and load the code into CalcPrimesVB.dll: A .NET assembly dll-file DotNet_LoadVBcode( FileRead( "CalcPrimesVB.vb" ), "System.dll", 0, "CalcPrimesVB.dll" ) ; You can delete the PDB-file (binary file containing debug information) If you inspect the dll-file with ILSpy.exe (see DotNet.au3 UDF) you'll see these comments in top of the output in the right pane window: // ...\7) Create DLL\Prime numbers\VB\CalcPrimesVB.dll // CalcPrimesVB, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Global type: <Module> // Architecture: AnyCPU (64-bit preferred) // Runtime: .NET 4.0 Note that the dll-file can be used in both 32 and 64 bit code (Architecture: AnyCPU). The second step is to modify the AutoIt/VB UDF to load the code from the dll-file: #include-once #include "..\..\..\..\..\Includes\DotNetAll.au3" Func CalcPrimesVBInit() CalcPrimesVB( 0 ) EndFunc Func CalcPrimesVB( $nPrimes ) Static $oNetCode = 0, $oPrimesClass = 0 If $nPrimes = 0 Or $oNetCode = 0 Then ; Load CalcPrimesVB.dll and create PrimesClass object $oNetCode = DotNet_LoadAssembly( "CalcPrimesVB.dll" ) $oPrimesClass = DotNet_CreateObject( $oNetCode, "PrimesClass" ) If $nPrimes = 0 Then Return EndIf ; Execute CalcPrimes method and return 1D array of primes Return $oPrimesClass.CalcPrimes( $nPrimes ) EndFunc The user code in the examples is exactly the same. But in a production environment the AutoIt user code is usually compiled into an exe-file. Please compile the user code and double click the exe-file to run it. If the AutoIt user code is compiled into an exe-file and the VB dll-file is stored in the same folder as the exe-file, the AutoIt code is always able to find and load the VB dll-file. Summary C# and VB code through .NET Framework is without any doubt the absolute easiest way to execute compiled code in an AutoIt script. It's especially easy because everything (write, compile, load and execute the code and even create an assembly dll-file) can be done through AutoIt. There is no need for any external tools at all. Usually, only 2 lines of AutoIt code are required to make the compiled code available in an AutoIt script. When it comes to calculations and array manipulations, the difference between C#/VB code and AutoIt code is not that big. Under development of C#/VB code (debug) information can be written to SciTE console or a message box. Syntax errors in the code are reported in SciTE console. Because the compiled code is executed as object methods, this solves an otherwise impossible problem of passing arrays back and forth between AutoIt code and compiled code. Posts below Real C# and VB examples. Four examples about generating a 2D array of random data, sorting the array by one or more columns through an index, converting the 2D array to a 1D array in CSV format, and finally saving the 1D array as a CSV file. Post 2. UDF version of examples in post 2. Also a version with a .NET assembly dll-file. Post 3. Adv. C# and VB examples. An introduction to threading. Post 4. Some considerations regarding calculation of prime numbers. Post 7. Optimizing C# and VB code. Optimizing code through multithreading. Optimizing code by storing array as global variable in VB code, thereby avoiding spending time passing arrays back and forth between AutoIt code and VB code. Post 8. Zip-file The zip-file contains two folders: Examples\ and Includes\. Includes\ only contains DotNetAll.au3. You need AutoIt 3.3.10 or later. Tested on Windows 10, Windows 7 and Windows XP. Comments are welcome. Let me know if there are any issues. UsingCSandVB.7z1 point
-
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. When I first got the dll compiled I couldn't get it to generate code in flat binary format. It was working but size of output was over 300 bytes no matter what the assembly code and could just tell it was outputting a different format than binary. Eventually I figured out that within the primary "include\win32ax.inc"', it executes a macro "format PE GUI 4.0" if x86 has not been defined. I underlined macro there because at first I (wasted shit loads of time because I) didn't realize it was a macro (adding a bunch of other includes) since in version 1 the statement "format binary" was a default if not specified and specifically means add nothing extra to the code. So long story short, the part that I was missing is including the cpu type and extensions from include\cpu folder. By default I add x64 type and SSE4 ext includes. Note that the x64 here is not about what mode we are running in, this is for what instructions your cpu supports. if you are running on some really old hardware that may need to be adjusted or if your on to more advanced instructions like the avx extensions, you may have to add those includes to your source. 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 _main stdcall, pAdd') _(' mov eax, [pAdd]') _(' mov dword[eax], _crc32') _(' mov dword[eax+4], _strlen') _(' mov dword[eax+8], _strcmp') _(' mov dword[eax+12], _strstr') _(' ret') _('endp') _('EQUAL_ORDERED = 1100b') _('EQUAL_ANY = 0000b') _('EQUAL_EACH = 1000b') _('RANGES = 0100b') _('NEGATIVE_POLARITY = 010000b') _('BYTE_MASK = 1000000b') _('align 8') _('proc _crc32 uses ebx ecx esi, pStr') _(' mov esi, [pStr]') _(' xor ebx, ebx') _(' not ebx') _(' stdcall _strlen, esi') _(' .while eax >= 4') _(' crc32 ebx, dword[esi]') _(' add esi, 4') _(' sub eax, 4') _(' .endw') _(' .while eax') _(' crc32 ebx, byte[esi]') _(' inc esi') _(' dec eax') _(' .endw') _(' not ebx') _(' mov eax, ebx') _(' ret') _('endp') _('align 8, 0xCC') ; fill with 0xCC instead of NOP _('proc _strlen uses ecx edx, pStr') _(' mov ecx, [pStr]') _(' mov edx, ecx') _(' mov eax, -16') _(' pxor xmm0, xmm0') _(' .repeat') _(' add eax, 16') _(' pcmpistri xmm0, dqword[edx + eax], 1000b') ;EQUAL_EACH') _(' .until ZERO?') ; repeat loop until Zero flag (ZF) is set _(' add eax, ecx') ; add remainder _(' ret') _('endp') _('align 8') _('proc _strcmp uses ebx ecx edx, pStr1, pStr2') ; ecx = string1, edx = string2' _(' mov ecx, [pStr1]') ; ecx = start address of str1 _(' mov edx, [pStr2]') ; edx = start address of str2 _(' mov eax, ecx') ; eax = start address of str1 _(' sub eax, edx') ; eax = ecx - edx | eax = start address of str1 - start address of str2 _(' sub edx, 16') _(' mov ebx, -16') _(' STRCMP_LOOP:') _(' add ebx, 16') _(' add edx, 16') _(' movdqu xmm0, dqword[edx]') _(' pcmpistri xmm0, dqword[edx + eax], EQUAL_EACH + NEGATIVE_POLARITY') ; EQUAL_EACH + NEGATIVE_POLARITY ; find the first *different* bytes, hence negative polarity' _(' ja STRCMP_LOOP') ;a CF or ZF = 0 above _(' jc STRCMP_DIFF') ;c cf=1 carry _(' xor eax, eax') ; the strings are equal _(' ret') _(' STRCMP_DIFF:') _(' mov eax, ebx') _(' add eax, ecx') _(' ret') _('endp') _('align 8') _('proc _strstr uses ecx edx edi esi, sStrToSearch, sStrToFind') _(' mov ecx, [sStrToSearch]') _(' mov edx, [sStrToFind]') _(' pxor xmm2, xmm2') _(' movdqu xmm2, dqword[edx]') ; load the first 16 bytes of neddle') _(' pxor xmm3, xmm3') _(' lea eax, [ecx - 16]') _(' STRSTR_MAIN_LOOP:') ; find the first possible match of 16-byte fragment in haystack') _(' add eax, 16') _(' pcmpistri xmm2, dqword[eax], EQUAL_ORDERED') _(' ja STRSTR_MAIN_LOOP') _(' jnc STRSTR_NOT_FOUND') _(' add eax, ecx ') ; save the possible match start') _(' mov edi, edx') _(' mov esi, eax') _(' sub edi, esi') _(' sub esi, 16') _(' @@:') ; compare the strings _(' add esi, 16') _(' movdqu xmm1, dqword[esi + edi]') _(' pcmpistrm xmm3, xmm1, EQUAL_EACH + NEGATIVE_POLARITY + BYTE_MASK') ; mask out invalid bytes in the haystack _(' movdqu xmm4, dqword[esi]') _(' pand xmm4, xmm0') _(' pcmpistri xmm1, xmm4, EQUAL_EACH + NEGATIVE_POLARITY') _(' ja @b') _(' jnc STRSTR_FOUND') _(' sub eax, 15') ;continue searching from the next byte _(' jmp STRSTR_MAIN_LOOP') _(' STRSTR_NOT_FOUND:') _(' xor eax, eax') _(' ret') _(' STRSTR_FOUND:') _(' sub eax, [sStrToSearch]') _(' inc eax') _(' ret') _('endp') Listing Output: 00000000: use32 00000000: 55 89 E5 procf _main stdcall, pAdd 00000003: 8B 45 08 mov eax, [pAdd] 00000006: C7 00 28 00 00 00 mov dword[eax], _crc32 0000000C: C7 40 04 68 00 00 00 mov dword[eax+4], _strlen 00000013: C7 40 08 90 00 00 00 mov dword[eax+8], _strcmp 0000001A: C7 40 0C D8 00 00 00 mov dword[eax+12], _strstr 00000021: C9 C2 04 00 ret 00000025: localbytes = current 00000025: purge ret?,locals?,endl?,proclocal? 00000025: end namespace 00000025: purge endp? 00000025: EQUAL_ORDERED = 1100b 00000025: EQUAL_ANY = 0000b 00000025: EQUAL_EACH = 1000b 00000025: RANGES = 0100b 00000025: NEGATIVE_POLARITY = 010000b 00000025: BYTE_MASK = 1000000b 00000025: 0F 1F 00 align 8 00000028: 55 89 E5 53 51 56 proc _crc32 uses ebx ecx esi, pStr 0000002E: 8B 75 08 mov esi, [pStr] 00000031: 31 DB xor ebx, ebx 00000033: F7 D3 not ebx 00000035: 56 E8 2D 00 00 00 stdcall _strlen, esi 0000003B: 83 F8 04 72 0D .while eax >= 4 00000040: F2 0F 38 F1 1E crc32 ebx, dword[esi] 00000045: 83 C6 04 add esi, 4 00000048: 83 E8 04 sub eax, 4 0000004B: EB EE .endw 0000004D: 85 C0 74 09 .while eax 00000051: F2 0F 38 F0 1E crc32 ebx, byte[esi] 00000056: 46 inc esi 00000057: 48 dec eax 00000058: EB F3 .endw 0000005A: F7 D3 not ebx 0000005C: 89 D8 mov eax, ebx 0000005E: 5E 59 5B C9 C2 04 00 ret 00000065: localbytes = current 00000065: purge ret?,locals?,endl?,proclocal? 00000065: end namespace 00000065: purge endp? 00000065: CC CC CC align 8, 0xCC 00000068: 55 89 E5 51 52 proc _strlen uses ecx edx, pStr 0000006D: 8B 4D 08 mov ecx, [pStr] 00000070: 89 CA mov edx, ecx 00000072: B8 F0 FF FF FF mov eax, -16 00000077: 66 0F EF C0 pxor xmm0, xmm0 0000007B: .repeat 0000007B: 83 C0 10 add eax, 16 0000007E: 66 0F 3A 63 04 02 08 pcmpistri xmm0, dqword[edx + eax], 1000b 00000085: 75 F4 .until ZERO? 00000087: 01 C8 add eax, ecx 00000089: 5A 59 C9 C2 04 00 ret 0000008F: localbytes = current 0000008F: purge ret?,locals?,endl?,proclocal? 0000008F: end namespace 0000008F: purge endp? 0000008F: 90 align 8 00000090: 55 89 E5 53 51 52 proc _strcmp uses ebx ecx edx, pStr1, pStr2 00000096: 8B 4D 08 mov ecx, [pStr1] 00000099: 8B 55 0C mov edx, [pStr2] 0000009C: 89 C8 mov eax, ecx 0000009E: 29 D0 sub eax, edx 000000A0: 83 EA 10 sub edx, 16 000000A3: BB F0 FF FF FF mov ebx, -16 000000A8: STRCMP_LOOP: 000000A8: 83 C3 10 add ebx, 16 000000AB: 83 C2 10 add edx, 16 000000AE: F3 0F 6F 02 movdqu xmm0, dqword[edx] 000000B2: 66 0F 3A 63 04 02 18 pcmpistri xmm0, dqword[edx + eax], EQUAL_EACH + NEGATIVE_POLARITY 000000B9: 77 ED ja STRCMP_LOOP 000000BB: 72 09 jc STRCMP_DIFF 000000BD: 31 C0 xor eax, eax 000000BF: 5A 59 5B C9 C2 08 00 ret 000000C6: STRCMP_DIFF: 000000C6: 89 D8 mov eax, ebx 000000C8: 01 C8 add eax, ecx 000000CA: 5A 59 5B C9 C2 08 00 ret 000000D1: localbytes = current 000000D1: purge ret?,locals?,endl?,proclocal? 000000D1: end namespace 000000D1: purge endp? 000000D1: 0F 1F 80 00 00 00 00 align 8 000000D8: 55 89 E5 51 52 57 56 proc _strstr uses ecx edx edi esi, sStrToSearch, sStrToFind 000000DF: 8B 4D 08 mov ecx, [sStrToSearch] 000000E2: 8B 55 0C mov edx, [sStrToFind] 000000E5: 66 0F EF D2 pxor xmm2, xmm2 000000E9: F3 0F 6F 12 movdqu xmm2, dqword[edx] 000000ED: 66 0F EF DB pxor xmm3, xmm3 000000F1: 8D 41 F0 lea eax, [ecx - 16] 000000F4: STRSTR_MAIN_LOOP: 000000F4: 83 C0 10 add eax, 16 000000F7: 66 0F 3A 63 10 0C pcmpistri xmm2, dqword[eax], EQUAL_ORDERED 000000FD: 77 F5 ja STRSTR_MAIN_LOOP 000000FF: 73 30 jnc STRSTR_NOT_FOUND 00000101: 01 C8 add eax, ecx 00000103: 89 D7 mov edi, edx 00000105: 89 C6 mov esi, eax 00000107: 29 F7 sub edi, esi 00000109: 83 EE 10 sub esi, 16 0000010C: @@: 0000010C: 83 C6 10 add esi, 16 0000010F: F3 0F 6F 0C 3E movdqu xmm1, dqword[esi + edi] 00000114: 66 0F 3A 62 D9 58 pcmpistrm xmm3, xmm1, EQUAL_EACH + NEGATIVE_POLARITY + BYTE_MASK 0000011A: F3 0F 6F 26 movdqu xmm4, dqword[esi] 0000011E: 66 0F DB E0 pand xmm4, xmm0 00000122: 66 0F 3A 63 CC 18 pcmpistri xmm1, xmm4, EQUAL_EACH + NEGATIVE_POLARITY 00000128: 77 E2 ja @b 0000012A: 73 0F jnc STRSTR_FOUND 0000012C: 83 E8 0F sub eax, 15 0000012F: EB C3 jmp STRSTR_MAIN_LOOP 00000131: STRSTR_NOT_FOUND: 00000131: 31 C0 xor eax, eax 00000133: 5E 5F 5A 59 C9 C2 08 00 ret 0000013B: STRSTR_FOUND: 0000013B: 2B 45 08 sub eax, [sStrToSearch] 0000013E: 40 inc eax 0000013F: 5E 5F 5A 59 C9 C2 08 00 ret 00000147: localbytes = current 00000147: purge ret?,locals?,endl?,proclocal? 00000147: end namespace 00000147: purge endp? 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 Added fastcall support for Ifex Corrected missing include file include\macro\if.inc within win64au3.inc fasmg 5-19-2020.zip Previous versions:1 point
-
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: _('procf _Bounce uses ebx, pParms') ; ; create the local variables _(' locals') _(' BlankCell db 32') ; this first group covers the variables from the original script _(' MyCell db ?') _(' OldCell db ?') _(' MyAtt dw ?') _(' OldAtt dw ?') _(' tCoords COORD') _(' tDelta COORD') _(' tOld COORD') _(' bytesread dw ?') ; _(' iMyID dw ?') ; this group of local vars cover holding all the other paramerters we are passing in tParms _(' g_hScreenMutex dd ?') _(' g_hRunMutex dd ?') _(' g_hStdHandle dd ?') _(' pfWaitForSingleObject dd ?') _(' pfReleaseMutex dd ?') _(' pfReadChar dd ?') _(' pfReadAttr dd ?') _(' pfWriteChar dd ?') _(' pfWriteAttr dd ?') _(' endl') ; ;all of these push/pops are to transfer the rest of variables from tParms structure to the local variables we created ;first mov the structure address into ebx _(' mov ebx, [pParms]') ; ; now push and pop the values into the variables ; use _winapi_displaystruct() to view all the offsets being used in the [ebx+offset] lines _(' pushw [ebx]') ; _(' popw word[tCoords+COORD.X]') _(' pushw word[ebx+2]') ; _(' popw word[tCoords+COORD.Y]') _(' pushw word[ebx+4]') ; _(' popw word[tDelta+COORD.X]') _(' pushw word[ebx+6]') ; _(' popw word[tDelta+COORD.Y]') _(' pushw word[ebx+8]') ; _(' popw word[iMyID]') _(' push dword[ebx+12]') ; _(' pop dword[g_hScreenMutex]') _(' push dword[ebx+16]') ; _(' pop dword[g_hRunMutex]') _(' push dword[ebx+20]') ; _(' pop dword[g_hStdHandle]') _(' push dword[ebx+24]') ; _(' pop dword[pfWaitForSingleObject]') _(' push dword[ebx+28]') ; _(' pop dword[pfReleaseMutex]') _(' push dword[ebx+32]') ; _(' pop dword[pfReadChar]') _(' push dword[ebx+36]') ; _(' pop dword[pfReadAttr]') _(' push dword[ebx+40]') ; _(' pop dword[pfWriteChar]') _(' push dword[ebx+44]') ; _(' pop dword[pfWriteAttr]') _('.if word[iMyID] > 16') ; $tMyCell.mc = $iMyID > 16 ? 0x01 : 0x02 (no difference in windows 10) _(' mov word[MyCell], 1') _('.else') _(' mov word[MyCell], 2') _('.endif') ; _('pushw word[iMyID]') ; $tMyAttrib.ma = BitAND($iMyID, 0x0F) _('popw word[MyAtt]') _('and word[MyAtt], 15') ; _('.repeat') ; do ; ; Wait infinetly for the screen mutex to be available, then take ownership _(' invoke pfWaitForSingleObject, [g_hScreenMutex], -1') ; ; DllCall('kernel32.dll', "bool", "WriteConsoleOutputCharacter", "handle", $hStdHandle, "byte*", 0x20, "dword", 1, "struct", $tOld, "dword*", 0) _(' invoke pfReadChar, [g_hStdHandle], addr OldCell, 1, dword[tOld], addr bytesread') ; _(' invoke pfReadAttr, [g_hStdHandle], addr OldAtt, 1, dword[tOld], addr bytesread') ; ; _(' mov al, byte[MyCell]') ;If ($tOldCell.oc = $tMyCell.mc) And ($tOldAttrib.oa = $tMyAttrib.ma) Then _(' mov cl, byte[MyAtt]') _(' .if (byte[OldCell] = al) & (byte[OldAtt] = cl)') _(' invoke pfWriteChar, [g_hStdHandle], addr BlankCell, 1, dword[tOld], addr bytesread') _(' .endif') ; ; DllCall('kernel32.dll', "bool", "WriteConsoleOutputCharacter", "handle", $hStdHandle, "struct*", $tMyCell, "dword", 1, "struct", $tCoords, "dword*", 0) _(' invoke pfWriteChar, [g_hStdHandle], addr MyCell, 1, dword[tCoords], addr bytesread') _(' invoke pfWriteAttr, [g_hStdHandle], addr MyAtt, 1, dword[tCoords], addr bytesread') ; _(' pushw word[tCoords+COORD.X]') ;$tOld.X = $tCoords.X _(' popw word[tOld+COORD.X]') ; _(' pushw word[tCoords+COORD.Y]') ;$tOld.Y = $tCoords.Y _(' popw word[tOld+COORD.Y]') _(' mov ax, word[tDelta+COORD.X]') ; $tCoords.X += $tDelta.X _(' add word[tCoords+COORD.X], ax') ; _(' mov ax, word[tDelta+COORD.Y]') ; $tCoords.Y += $tDelta.Y _(' add word[tCoords+COORD.Y], ax') ; ; If $tCoords.X < 0 Or $tCoords.X >= 120 Then $tDelta.X *= -1 _(' .if (word[tCoords+COORD.X] < 0 | word[tCoords+COORD.X] >= 120)') _(' neg word[tDelta+COORD.X]') _(' .endif') _(' .if (word[tCoords+COORD.Y] < 0 | word[tCoords+COORD.Y] >= 30)') _(' neg word[tDelta+COORD.Y]') _(' .endif') ; ; release the screen mutex _(' invoke pfReleaseMutex, [g_hScreenMutex]') ; ; wait 100 ms for the Runmutex to be available. _(' invoke pfWaitForSingleObject, [g_hRunMutex], 100') ; ; a return of 258 means it timed out waiting and that the run mutex (owned by the main autoit thread) is still alive. ; when the run mutex handle gets closed this will return a fail or abandonded. _('.until eax <> 258') ; ;exit thread _(' ret') _('endp') And finally how we call that assembled function from autoit to create the theads: ;create mutex for sharing the screen thats not owned by main thread Global $g_hScreenMutex = _WinAPI_CreateMutex('', False) ; ;create mutex that tells the threads to exit that is owned by main thread Global $g_hRunMutex = _WinAPI_CreateMutex('', True) ... ... ;assemble function Local $tBinExec = _fasmg_Assemble($g_sFasm, False) ;Local $tBinExec = _fasmg_CompileAu3($g_sFasm) If @error Then Exit (ConsoleWrite($tBinExec & @CRLF)) ;this is struct is for all the values Im passing to the thread. ;this will hold are random start x,y,delta values, handles, and pointers to functions called within the thread $tParms = DllStructCreate('short start[4];word myid;dword hands[3];ptr funcs[6]') $tParms.start(1) = Random(0, 119, 1) $tParms.start(2) = Random(0, 29, 1) $tParms.start(3) = Random(-3, 3, 1) $tParms.start(4) = Random(-3, 3, 1) $tParms.myid = 1 $tParms.hands(1) = $g_hScreenMutex $tParms.hands(2) = $g_hRunMutex $tParms.hands(3) = $g_hStdHandle $tParms.funcs(1) = _GPA('kernel32.dll', 'WaitForSingleObject') $tParms.funcs(2) = _GPA('kernel32.dll', 'ReleaseMutex') $tParms.funcs(3) = _GPA('kernel32.dll', 'ReadConsoleOutputCharacterA') $tParms.funcs(4) = _GPA('kernel32.dll', 'ReadConsoleOutputAttribute') $tParms.funcs(5) = _GPA('kernel32.dll', 'WriteConsoleOutputCharacterA') $tParms.funcs(6) = _GPA('kernel32.dll', 'WriteConsoleOutputAttribute') ;create 128 threads with different start values and colors for each one For $i = 1 To 128 $tParms.myid = $i $tParms.start(1) = Random(0, 119, 1) $tParms.start(2) = Random(0, 29, 1) $tParms.start(3) = Random(-3, 3, 1) $tParms.start(4) = Random(-3, 3, 1) If $tParms.start(3) + $tParms.start(4) = 0 Then $tParms.start(3) = (Mod(@MSEC, 2) ? 1 : -1) ; adjusting non-moving (0,0) delta values.. DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, "struct*", $tBinExec, "struct*", $tParms, "dword", 0, "dword*", 0) Sleep(50) Next MsgBox(262144, '', '128 Threads Created') ;Close the run mutex handle. This will cause all the threads to exit _WinAPI_CloseHandle($g_hRunMutex) _WinAPI_CloseHandle($g_hScreenMutex) MsgBox(262144, '', 'Mutex handles closed. All Threads should have exited') Exit The attachment below contains both the compiled and source assembly. To play with the assembly source you need to add the fasmg udf in my sig. The compiled version should not need anything. Let me know if you have any issues. Special thanks to @trancexx for teaching me this with her clock example Bounce.zip1 point
-
I will try to maintain this topic by inserting links in the first post (here) to the snippets to keep track of the snippets. My examples are using AndyG's AssembleIt UDF / AssembleIt2 UDF which is here: AssembleIt.au3 (needs FASM.au3 -> see link below (ward)) ;AssembleIt by Andy @ www.autoit.de ;BIG thx to progandy for the "Buttons" in the debugger ;see examples how to call _AssembleIt() ;Listview changed in Debugger 12.05.2012 ;SSE-Register are nor in the right direction (bitwise from right to left) 20.02.2012 ;Debugger included 07.04.2011 ;modified by UEZ 05.03.2015 #include-once #include "FASM.au3" #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> ;#include <GUIListBox.au3> #include <GuiStatusBar.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <array.au3> #include <GuiListView.au3> #include <WinAPI.au3> ;Opt("MustDeclareVars", 1) If @AutoItX64 Then MsgBox(0, "_AssembleIt Error", "Sorry, 64Bit is not supported. Program will be terminated!") Exit EndIf Global $_ASSEMBLEIT_FLAG = 1 Global $Fasm = FasmInit() If @error Then MsgBox(0, "_AssembleIt Error", "Not able to FasmInit! Program will be terminated!") Exit EndIf ; #FUNCTION# ====================================================================================== ; Name ..........: _AssembleIt() ; Description ...: "Wrapper" for the FASM.au3 by Ward ; Syntax ........: _AssembleIt($Returntype, $sFunc, $Type1 = "type", $Param1 = 0, $Type2 = "type", $Param2 = 0.... ; Parameters ....: $Returntype - Data type returned by the assembled program ; $sFunc - Name of the function, in which the Assemblercode is contained ; $sType1 - DataType of Parameter1 ; $sParam1 - Parameter1 ; $sType2 - DataType of Parameter2 ; $sParam2 - Parameter2.....and so on, you can pass up to 20 parameters ; ; Return values .: Success depends on $Returntype @error=0 ; Failure @error = -2 FasmReset has failed ; Failure @error = -3 Error in Assemblercode detected by Fasm ; Failure @error = -4 Function with Assemblercode doesn´t exist (i.e. wrong functionname) ; Failure @error = -5 Error while executing MemoryFuncCall ; ; Author ........: Andy @ www.autoit.de ; Modified ......: ; Remarks .......: _AssembleIt() instructs MemoryFuncCall with cdecl-convention, so only a RET is necessary at the end of the ASM-code ; If $_ASSEMBLEIT_FLAG = 0 is set before calling AssembleIt(), an AutoIt-code to call the opcodes without the need of FASM.au3 is created ; Related .......: Fasm.au3 by Ward http://www.autoitscript.com/forum/index.php?showtopic=111613&view=findpost&p=782727 ; Link ..........: ; Example .......: ; ================================================================================================= Func _AssembleIt($Returntype, $sFunc, $Type1 = "int", $Param1 = 0, $Type2 = "int", $Param2 = 0, $Type3 = "int", $Param3 = 0, $Type4 = "int", $Param4 = 0, $Type5 = "", $Param5 = 0, $Type6 = "", $Param6 = 0, $Type7 = "", $Param7 = 0, $Type8 = "", $Param8 = 0, $Type9 = "", $Param9 = 0, $Type10 = "", $Param10 = 0, $Type11 = "", $Param11 = 0, $Type12 = "", $Param12 = 0, $Type13 = "", $Param13 = 0, $Type14 = "", $Param14 = 0, $Type15 = "", $Param15 = 0, $Type16 = "", $Param16 = 0, $Type17 = "", $Param17 = 0, $Type18 = "", $Param18 = 0, $Type19 = "", $Param19 = 0, $Type20 = "", $Param20 = 0) ;assembles the code FasmReset($Fasm) If @error Then MsgBox(0, "_AssembleIt Error", "Error in Function FasmReset()") Return SetError(-2, 0, "ERROR -2") EndIf If $sFunc <> "" Then Call($sFunc) ;extract Assemblercode from function $sFunc() If @error = 0xDEAD Then MsgBox(0, "_AssembleIt Error", "The called function " & $sFunc & " doesn´t exist or contains errors!") Return SetError(-4, 0, "ERROR -4") EndIf Local $bytecode = FasmGetBinary($Fasm) ;assemble ASM-code to opcodes If @extended Then ;shows errors during assembling Local $Error = FasmGetLastError() ;gets errors MsgBox(0, "FASM-ERROR in function " & $sFunc & "()", "Error Code:" & $Error[0] & _ @CRLF & "Error Message:" & $Error[1] & @CRLF & "Error Line:" & $Error[2] & @CRLF) Return SetError(-3, 0, "ERROR -3") Else ;no errors during assembling the code FileDelete("asm_test.bin") ;creates binary file with opcodes, in the case that someone wants to use an external debugger^^ FileWrite("asm_test.bin", BinaryToString(String(FasmGetBinary($Fasm)))) ; ConsoleWrite($bytecode & @CRLF) ;opcodes, can easily be copied and inserted somewhere.... If $_ASSEMBLEIT_FLAG = 0 Then ;if less then 4 parameters, CallWindowProcW is possible If @NumParams > 10 Then ;only a maximum of 4 parameters in CallWindowProcW posssible MsgBox(0, "_AssembleIt Error", "The $_ASSEMBLEIT_FLAG is set to 0, but more than 4 Parameters are used in the Function " & $sFunc & @CRLF & _ "Please reduce the number of parameters to a maximum of 4 if you want an AutoItscript with a CallWindowProcW-call!") Exit Else ;all is ready to create an AutoItscript which can execute the opcodes without FASM.au3 Local $scriptstring = 'Local $iRet, $tCodeBuffer = DllStructCreate("byte ASM[' & StringLen($bytecode) / 2 - 1 & ']") ;reserve memory for ASM opcodes' & @CRLF & _ '$tCodeBuffer.ASM = "' & $bytecode & '" ;write opcodes into memory (struct)' & @CRLF $scriptstring &= '$iRet = DllCall("user32.dll", "' & $Returntype & '", "CallWindowProcW", "ptr", DllStructGetPtr($tCodeBuffer)' Local $n = 1 For $i = 3 To 9 Step 2 ;CallWindowProcW must be called with 4 parameters... $scriptstring &= ', "' & Eval("Type" & $n) & '", ' If Eval("Param" & $n) <> 0 Or Eval("Param" & $n) <> "" Then $scriptstring &= "Param" & $n Else $scriptstring &= '0' EndIf $n += 1 Next $scriptstring &= ')' & @CRLF ClipPut($scriptstring) ;puts the AutoItcode into Clipboard MsgBox(0, "_AssembleIt() Info!", "The following code was created and written into the Clipboard:" & _ @CRLF & @CRLF & $scriptstring & @CRLF & @CRLF & @CRLF & _ "This code can now be inserted into an AutoIt-Script, please adapt the parameters in the Dll-call to the used AutoIt-variables!" & _ @CRLF & "The Program will be terminated!") FasmExit($Fasm) Exit EndIf ElseIf $_ASSEMBLEIT_FLAG = 2 Then $scriptstring = '$tCodeBuffer.ASM = "' & $bytecode & '" ;write opcodes into memory (struct) / length: ' & StringLen($bytecode) / 2 - 1 ClipPut($scriptstring) MsgBox(0, "_AssembleIt() Info!", "ONLY the byte code line was created and written into the Clipboard:" & _ @CRLF & @CRLF & $scriptstring) FasmExit($Fasm) Exit EndIf ;MemoryFuncCall Local $scriptstring = 'MemoryFuncCall("' & $Returntype & ':cdecl",' & FasmGetFuncPtr($Fasm) ;cdecl instructs the function to clean the stack, only a simple RET at the end is necessary ;Local $scriptstring = 'MemoryFuncCall("' & $Returntype & '",' & FasmGetFuncPtr($Fasm) ;if "compatible" mode to existing programs is required, please commend out this line Local $n = 1 For $i = 3 To @NumParams Step 2 ;all parameters $scriptstring &= ',"' & Eval("Type" & $n) & '", $Param' & $n $n += 1 Next $scriptstring &= ')' Local $a = Execute($scriptstring) ;do the MemoryFuncCall, execute the opcodes If @error Then MsgBox(0, "_AssembleIt Error", "Error executing the MemoryFuncCall!") Return SetError(-5, 0, "ERROR -5") EndIf ;_arraydisplay($a) Return SetError(0, 0, $a[0]) EndIf EndFunc ;==>_AssembleIt Func _($str) ;short version of Fasmadd Fasmadd($Fasm, $str) EndFunc ;==>_ ;debug-Fenster Dim $_DBG_LABEL[170] Global $hwnd_weiterbutton, $_DBG_closebutton Global $_DBG_firstcall = True, $_DBG_buttonID Global $_DBG_GUI = GUICreate("AssembleIt Debug-Info 1.0", 670, 550, 10, 10, 0, $WS_EX_DLGMODALFRAME) Global $_DBG_winpos = WinGetPos($_DBG_GUI) Global $_DBG_Window_posold_x = $_DBG_winpos[0] ;fensterposition merken Global $_DBG_Window_posold_y = $_DBG_winpos[1] + $_DBG_winpos[3] ;$WM_MOVING = 0x0216 Global $_DBG_BUTTONSGUI = -1 GUIRegisterMsg(0x0216, "_DBG_WM_MOVING") ; $WM_MOVING GUIRegisterMsg(0x0232, "_DBG_WM_MOVING") ; $WM_EXITSIZEMOVE GUIRegisterMsg($WM_MOVE, "_DBG_WM_MOVING") ;~ GUIRegisterMsg($WM_MOVING, "_DBG_WM_MOVING") ;~ GUIRegisterMsg($WM_SIZE, "_DBG_WM_SIZE") ;GUIRegisterMsg($WM_COMMAND, "_DBG_WM_COMMAND") $_DBG_LABEL[18] = GUICtrlCreateLabel("FPU-Register showed as DOUBLE!", 10, 175, 290, 16) GUICtrlSetFont(-1, -1, -1, 4) ;GUICtrlSetResizing ( -1, 32+ 2 ) $_DBG_LABEL[17] = GUICtrlCreateLabel("EFlags", 580, 16, 102, 16) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[38] = GUICtrlCreateLabel("CF =", 580, 32 + 16 * 0, 30, 16);CF $_DBG_LABEL[59] = GUICtrlCreateLabel("DF =", 580, 32 + 16 * 1, 30, 16) $_DBG_LABEL[39] = GUICtrlCreateLabel("PF =", 580, 32 + 16 * 2, 30, 16) $_DBG_LABEL[68] = GUICtrlCreateLabel("OF =", 580, 32 + 16 * 3, 30, 16) $_DBG_LABEL[48] = GUICtrlCreateLabel("AF =", 580, 32 + 16 * 4, 30, 16) $_DBG_LABEL[49] = GUICtrlCreateLabel("ZF =", 580, 32 + 16 * 6, 30, 16) $_DBG_LABEL[58] = GUICtrlCreateLabel("SF =", 580, 32 + 16 * 7, 30, 16) For $i = 0 To 7 $_DBG_LABEL[10 + $i] = GUICtrlCreateLabel("ST" & $i & " = ", 10 + Mod($i, 2) * 180, 195 + 16 * Int($i / 2), 30, 16) $_DBG_LABEL[80 + $i] = GUICtrlCreateLabel("", 50 + Mod($i, 2) * 180, 195 + 16 * Int($i / 2), 100, 16) $_DBG_LABEL[30 + $i] = GUICtrlCreateLabel("XMM" & $i & " = ", 10, 400 + 15 * $i, 40, 16);XMM0-XMM7 $_DBG_LABEL[90 + $i] = GUICtrlCreateLabel("", 60, 400 + 15 * $i, 300, 16);XMM $_DBG_LABEL[40 + $i] = GUICtrlCreateLabel("", 60, 32 + 16 * $i, 400, 16);hex $_DBG_LABEL[50 + $i] = GUICtrlCreateLabel("", 150, 32 + 16 * $i, 400, 16);int $_DBG_LABEL[60 + $i] = GUICtrlCreateLabel("", 230, 32 + 16 * $i, 300, 16);float $_DBG_LABEL[70 + $i] = GUICtrlCreateLabel("", 320, 32 + 16 * $i, 240, 16);bin $_DBG_LABEL[100 + $i] = GUICtrlCreateLabel("", 610, 32 + 16 * $i, 40, 16) ;eflags $_DBG_LABEL[110 + $i] = GUICtrlCreateLabel("", 280, 400 + 15 * $i, 250, 16);XMM-2xdouble $_DBG_LABEL[120 + $i] = GUICtrlCreateLabel("", 440, 400 + 15 * $i, 250, 16);XMM-4xfloat Next GUICtrlSetPos($_DBG_LABEL[105], 590, 32 + 16 * 5, 1, 1) ;platz machen für ungenutztes label $_DBG_LABEL[20] = GUICtrlCreateLabel("FPU-Flags", 10, 270, 55, 16) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[21] = GUICtrlCreateLabel("CO= C1= C2=", 520, 200, 135, 20) $_DBG_LABEL[25] = GUICtrlCreateLabel("Stack", 370, 175, 130, 20) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[26] = GUICtrlCreateLabel("HEX", 450, 175, 130, 20) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[27] = GUICtrlCreateLabel("INT", 550, 175, 130, 20) GUICtrlSetFont(-1, -1, -1, 4) For $i = 40 To 0 Step -4 $_DBG_LABEL[129 + $i / 4] = GUICtrlCreateLabel(StringFormat("[esp %+02.2d]", 40 - $i), 370, 195 + 16 * $i / 4, 50, 16);129-140 $_DBG_LABEL[141 + $i / 4] = GUICtrlCreateLabel("", 450, 195 + 16 * $i / 4, 100, 16);141-152 $_DBG_LABEL[155 + $i / 4] = GUICtrlCreateLabel("", 550, 195 + 16 * $i / 4, 100, 16);155-161 Next $_DBG_LABEL[108] = GUICtrlCreateLabel("SSE-Register HEX", 10, 375, 150, 20) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[109] = GUICtrlCreateLabel("2x Double", 280, 375, 100, 20) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[118] = GUICtrlCreateLabel("4x Float", 450, 375, 100, 20) GUICtrlSetFont(-1, -1, -1, 4) ;GUIRegisterMsg($WM_COMMAND, "MyWM_COMMAND") Global $listviewitem_reg32[8] Global $reg_32[8] = ["EAX", "EBX", "ECX", "EDX", "ESI", "EDI", "ESP", "EBP"] Global $Listview_reg32 = GUICtrlCreateListView("REG32|HEX|INT|FLOAT|BIN [BIT31....Bit0]", 10, 2, 560, 172, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_NOSORTHEADER));,$GUI_BKCOLOR_LV_ALTERNATE ) GUICtrlSetFont(-1, 8.5, -1, -1) GUICtrlSetBkColor($Listview_reg32, 0xF0f0f0) ; Grau GUICtrlSetBkColor($Listview_reg32, $GUI_BKCOLOR_LV_ALTERNATE) _GUICtrlListView_BeginUpdate($Listview_reg32) For $i = 0 To 7 $listviewitem_reg32[$i] = GUICtrlCreateListViewItem($reg_32[$i] & "|0xDDDDDDDD|88888888888|9.99999999E999|00000000 00000000 00000000 00000000 ", $Listview_reg32) GUICtrlSetBkColor($listviewitem_reg32[$i], 0xFFFFFF) ; weiss Next For $i = 0 To 4 _GUICtrlListView_SetColumnWidth($Listview_reg32, $i, $LVSCW_AUTOSIZE_USEHEADER);$LVSCW_AUTOSIZE) Next _GUICtrlListView_EndUpdate($Listview_reg32) ;thx progandy für den "button" ! Global Const $tagDLGTEMPLATE = "align 2 ;DWORD style; DWORD dwExtendedStyle; WORD cdit; short x; short y; short cx; short cy;" Global Const $tagDLGITEMTEMPLATE = "align 2 ;DWORD style; DWORD dwExtendedStyle; short x; short y; short cx; short cy; WORD id;" Global $_DBG_noshowflag = 0 Global $dlgproc = DllCallbackRegister("_DlgProc", "bool", "hwnd;uint;wparam;lparam") Global $_DBG_ = DllCallbackRegister("_DBG_MSGBOX", "dword", "dword;dword;dword;dword;dword;dword;dword;dword;dword") ;speicher reservieren für datenbereich Global $ptr_dbgmem = Number(_MemGlobalAlloc(600, 0)) ;512 byte + 8 byte weil nur 8byte-align Local $mod = Mod($ptr_dbgmem, 16) ;benötigt wird für SSE-Register abe 16-byte-align If $mod <> 0 Then $ptr_dbgmem += (16 - $mod) ;16 byte align EndIf Global $_dbg_string[100], $_DBG_nr = 0, $_DBG_command[2] Global $struct_FXSAVE = DllStructCreate("byte[512]", $ptr_dbgmem);platz für Daten aus FXSAVE Global $struct_STACK = DllStructCreate("dword[11]", $ptr_dbgmem + 520);platz für Daten aus STACK [esp-20] bis [esp+20] Global $ptr_STACK = DllStructGetPtr($struct_STACK) ;http://siyobik.info/index.php?module=x86&id=128 ;ob ich diese flags noch einbaue, weiss ich nicht Local $struct = DllStructCreate("" & _ "word FCW;" & _ ;FPU control word 0+1 "word FSW;" & _ ;FPU statusword 2+3 "byte FTW;" & _ ;FPU ag word 4 "byte;" & _ ;reserved 5 "word FOP;" & _ ;FPU opcode 6+7 "dword FIP;" & _ ;FPU instruction pointer 8-11 "word CS;" & _ ; 12-13 "word ;" & _ ;reserved 14-15 "dword FDP;" & _ ; 16-19 "word DS;" & _ ; 20+21 "word ;" & _ ;reserved 22-23 "dword MXCSR;" & _ ;MXCSR 24-27 "dword MXCSR_MASK;" & _ ;MXCSR_MASK 28-31 "byte[10] ST0;") ;ST0 32-41 Global $struct_double = DllStructCreate("double[8]") ;platz für 8 doubles der FPU register st0-st7 Global $struct_128SSE = DllStructCreate("byte[128]", Ptr($ptr_dbgmem + 160));platz für 16 byte SSE Global $struct_EFLAGS = DllStructCreate("dword EFLAGS", Ptr($ptr_dbgmem + 512));platz 32 bit eflags Global $ptr_SSE = DllStructGetPtr($struct_128SSE) ;pointer Global $ptr_EFLAGS = DllStructGetPtr($struct_EFLAGS) Global $struct_SSE64x2int = DllStructCreate("uint64[16]", $ptr_SSE) ;platz für 2x 64byte SSE Global $struct_SSE32x4int = DllStructCreate("uint[32]", $ptr_SSE) ;platz für 4x 32byte SSE Global $struct_SSE16x8int = DllStructCreate("word[64]", $ptr_SSE) ;platz für 8x 16byte SSE Global $struct_SSE64x2dbl = DllStructCreate("double[16]", $ptr_SSE) ;platz für 2x 64byte DOUBLE SSE Global $struct_SSE32x4flt = DllStructCreate("float[32]", $ptr_SSE) ;platz für 4x 32byte FLOAT SSE ;debug-funktion, aus dem asmcode per call an die callback-adresse aufgerufen Func _DBG_MSGBOX($anz, $edi, $esi, $ebp, $esp, $ebx, $edx, $ecx, $eax);aus asm übergebene register If $_DBG_noshowflag = 1 Then Return 0 GUISetState(@SW_SHOW, $_DBG_GUI) _WinAPI_UpdateWindow($_DBG_GUI) ;_DBG_WM_SIZE($_DBG_GUI,0,0,0) Dim $reg[8] = [$eax, $ebx, $ecx, $edx, $esi, $edi, $esp, $ebp] _GUICtrlListView_BeginUpdate($Listview_reg32) For $i = 0 To 7 ;fenster mit Werten füllen GUICtrlSetData($listviewitem_reg32[$i], "|" & Ptr($reg[$i]) & "|" & _ String($reg[$i]) & "|" & _ StringFormat(" %2.6G", int2float($reg[$i])) & "|" & int2bin($reg[$i])) ;hex GUICtrlSetData($_DBG_LABEL[$i + 80], DllStructGetData($struct_double, 1, $i + 1));FPU st0-st7 ;SSE $struct_temp = DllStructCreate("byte[16]", $ptr_SSE + 16 * $i) $struct = DllStructCreate("byte[16]") For $z = 1 To 16 DllStructSetData($struct, 1, DllStructGetData($struct_temp, 1, 17 - $z), $z) Next GUICtrlSetData($_DBG_LABEL[$i + 90], DllStructGetData($struct, 1)) GUICtrlSetData($_DBG_LABEL[$i + 100], BitAND(2 ^ $i, DllStructGetData($struct_EFLAGS, 1)) / (2 ^ $i));eflags $struct = DllStructCreate("double[2]", $ptr_SSE + 16 * $i); 2x 64byte DOUBLE SSE GUICtrlSetData($_DBG_LABEL[$i + 110], StringFormat("%6s %6s", DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 1))) $struct = DllStructCreate("float[4]", $ptr_SSE + 16 * $i); 4x 32byte FLOAT SSE GUICtrlSetData($_DBG_LABEL[$i + 120], StringFormat("%10.5f %10.5f %10.5f %10.5f", DllStructGetData($struct, 1, 4), DllStructGetData($struct, 1, 3), DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 1))) Next GUICtrlSetData($_DBG_LABEL[101], BitAND(2 ^ 10, DllStructGetData($struct_EFLAGS, 1)) / (2 ^ 10));eflags DF GUICtrlSetData($_DBG_LABEL[103], BitAND(2 ^ 11, DllStructGetData($struct_EFLAGS, 1)) / (2 ^ 11));eflags OF For $i = 0 To 10 ;stack GUICtrlSetData($_DBG_LABEL[141 + $i], Ptr(DllStructGetData($struct_STACK, 1, $i + 1)));stack hex GUICtrlSetData($_DBG_LABEL[155 + $i], Int(DllStructGetData($struct_STACK, 1, $i + 1)));stack int Next _GUICtrlListView_EndUpdate($Listview_reg32) If $anz = 0 Or Execute($_dbg_string[$anz]) Then Switch __GET_MSGBOX_BUTTON() Case 0, 1 Case 2 $_DBG_noshowflag = True Case 3 DllCall("kernel32.dll", "none", "ExitProcess", "int", 0xDEADBEEF) EndSwitch EndIf Return 0 EndFunc ;==>_DBG_MSGBOX Func __GET_MSGBOX_BUTTON() Local Static $tDLG, $aOldPos[4] = [0, 0, -1, -1] Local $pos_DBB_Window = WinGetPos($_DBG_GUI) ;Positionsdaten der GUI holen If $aOldPos[0] <> $pos_DBB_Window[0] Or $aOldPos[1] <> $pos_DBB_Window[1] Or $aOldPos[2] <> $pos_DBB_Window[2] Or $aOldPos[2] <> $pos_DBB_Window[2] Then $aOldPos = $pos_DBB_Window Local $x = Int($pos_DBB_Window[0] / 2) Local $y = Int(($pos_DBB_Window[1] + $pos_DBB_Window[3]) / 2) ;es folgen die Daten für den "...NEXT"-Button, der muss ein modales Fenster sein, wer da eine andere Idee hat, bitte melden Local $w = Int($pos_DBB_Window[2] / 2) ;breite Button Local $h = 30 ;höhe Button Local $bTitle = StringToBinary("Next....", 2) ;text Button Local $bXY = BinaryMid(Binary($x), 1, 2) & BinaryMid(Binary($y), 1, 2);Buttondaten Local $bWH = BinaryMid(Binary($w), 1, 2) & BinaryMid(Binary($h), 1, 2) Local $bWhalfH = BinaryMid(Binary(Int($w / 2 - 15)), 1, 2) & BinaryMid(Binary($h), 1, 2) Local $bDIALOG = Binary("0x00000090400000040300") & $bXY & $bWH & Binary("0x000000000000") & Binary("0x000000500000000000000000") & $bWhalfH & Binary("0x0100FFFF8000") & $bTitle & Binary("0x0000") & Binary("0x0000") ; |Style ||ExStyl||cdit| |Empty "Arrays"| |Style ||ExStyl||x ||y | |id||BUTTON| |Chr0| |irgend welche anderen Arrays $x = Mod(BinaryLen($bDIALOG), 4) If $x Then $bDIALOG &= BinaryMid(Binary("0x000000"), 1, $x) $bTitle = StringToBinary("End Debugging", 2) ;text Button $bDIALOG &= Binary("0x0000005000000000") & BinaryMid(Int($w / 2 - 15), 1, 2) & Binary("0x0000") & $bWhalfH & Binary("0x0200FFFF8000") & $bTitle & Binary("0x0000") & Binary("0x0000") $x = Mod(BinaryLen($bDIALOG), 4) If $x Then $bDIALOG &= BinaryMid(Binary("0x000000"), 1, $x) $bTitle = StringToBinary("Kill", 2) ;text Button $bDIALOG &= Binary("0x0000005000000000") & BinaryMid(Int($w - 30), 1, 2) & Binary("0x0000") & BinaryMid(30, 1, 2) & BinaryMid($h, 1, 2) & Binary("0x0300FFFF8000") & $bTitle & Binary("0x0000") & Binary("0x0000") $tDLG = DllStructCreate("byte[" & BinaryLen($bDIALOG) & "]") DllStructSetData($tDLG, 1, $bDIALOG) ;Button-Daten in struct schreiben EndIf Local $aRet = DllCall("user32.dll", "int", "DialogBoxIndirectParamW", "ptr", 0, "ptr", DllStructGetPtr($tDLG), "hwnd", 0, "ptr", DllCallbackGetPtr($dlgproc), "lparam", 0) If @error Then Return 0 Return $aRet[0] EndFunc ;==>__GET_MSGBOX_BUTTON ;Alle Register, Flags, Stack usw werden in einen Speicherbereich geschrieben und von dort mit ;der Funktion _DBG_MSGBOX() ausgelesen Func _asmdbg_($_DBG_command = "") ;Register _("push dword[esp+40]") ;stack in memory _("pop dword[" & $ptr_STACK & "]") _("push dword[esp+36]") ;stack in memory _("pop dword[" & $ptr_STACK + 4 & "]") _("push dword[esp+32]") ;stack in memory _("pop dword[" & $ptr_STACK + 8 & "]") _("push dword[esp+28]") ;stack in memory _("pop dword[" & $ptr_STACK + 12 & "]") _("push dword[esp+24]") ;stack in memory _("pop dword[" & $ptr_STACK + 16 & "]") _("push dword[esp+20]") ;stack in memory _("pop dword[" & $ptr_STACK + 20 & "]") _("push dword[esp+16]") ;stack in memory _("pop dword[" & $ptr_STACK + 24 & "]") _("push dword[esp+12]") ;stack in memory _("pop dword[" & $ptr_STACK + 28 & "]") _("push dword[esp+08]") ;stack in memory _("pop dword[" & $ptr_STACK + 32 & "]") _("push dword[esp+04]") ;stack in memory _("pop dword[" & $ptr_STACK + 36 & "]") _("push dword[esp+00]") ;stack in memory _("pop dword[" & $ptr_STACK + 40 & "]") _("pushfd") ;eflags sichern _("pop dword[" & Ptr($ptr_EFLAGS) & "]") ;eflags speichern in struct _("pushfd") ;eflags sichern _("push eax") _("mov eax," & $ptr_dbgmem) ;alle FPU+SSE Registerinhalte und flags sichern _("FXSAVE [eax]") _("fstp qword[" & DllStructGetPtr($struct_double) & "]") ;alle FPU-Register sichern _("fstp qword[" & DllStructGetPtr($struct_double) + 8 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 16 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 24 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 32 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 40 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 48 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 56 & "]") ; _("fwait") _("pop eax") _("pushad") ;alle Register sichern _("pushad") ;auf den stack für für die msgbox If $_DBG_command <> "" Then ;falls kein Befehl übergeben wurde $_DBG_nr += 1 $_dbg_string[$_DBG_nr] = $_DBG_command _("push " & Ptr($_DBG_nr)) ;anzahl der Else _("push " & Ptr(0)) EndIf _("call " & DllCallbackGetPtr($_DBG_)) ;in autoit-callbackroutine springen _("mov eax," & $ptr_dbgmem) ;alle FPU+SSE registerinhalte und flags restore _("FXRSTOR [eax]") ;restore alle FPU-Register ; _("fwait") _("popad") ;alle register wieder zurücksetzen _("popfd") ;eflags setzen EndFunc ;==>_asmdbg_ Func bin2ascii($bin_string) ;string aus nullen und einsen in 8-bit-ascii text string umwandeln Local $step = 8 ;8-Bit ASCII Buchstaben Local $ascii_string = "" ;Rückgabestring For $f = 1 To StringLen($bin_string) Step $step ;string von Vorne nach hinten 8-bitweise durchsuchen Local $t = StringMid($bin_string, $f, $step) ; 8-Bit-Wort, ein ASCII-Buchstabe Local $bin = 0 ;startwert für For $i = 1 To $step ;jedes Bit suchen If StringMid($t, $i, 1) = "1" Then $bin += (2 ^ ($step - $i)) ;wenn Bit=1 dann binärzahl=binärzahl+2^(8-Bitposition) Next $ascii_string &= Chr($bin) Next Return $ascii_string EndFunc ;==>bin2ascii Func int2bin($integer) ;32Bit in binärstring darstellen Local $bin_string = "" For $i = 31 To 0 Step -1 ;asciicode in bits If Mod($i + 1, 8) = 0 Then $bin_string &= " " If BitAND($integer, 2 ^ $i) Then $bin_string &= "1" Else $bin_string &= "0" EndIf Next Return $bin_string EndFunc ;==>int2bin Func int2float($integer) Local $struct = DllStructCreate("int") Local $struct2 = DllStructCreate("float", DllStructGetPtr($struct)) DllStructSetData($struct, 1, $integer) Local $ret = DllStructGetData($struct2, 1) $struct = 0 $struct2 = 0 Return $ret EndFunc ;==>int2float Func _DlgProc($hwnd, $uMsg, $wParam, $lParam) ;thx to progandy! If $uMsg = $WM_INITDIALOG Then $_DBG_BUTTONSGUI = $hwnd ElseIf $uMsg = $WM_CLOSE Then DllCall("user32.dll", "bool", "EndDialog", "hwnd", $hwnd, "int_ptr", 0) Return True ElseIf $uMsg = $WM_COMMAND Then DllCall("user32.dll", "bool", "EndDialog", "hwnd", $hwnd, "int_ptr", BitAND($wParam, 0xFFFF)) Return True ElseIf $uMsg = $WM_DESTROY Then $_DBG_BUTTONSGUI = -1 EndIf Return False EndFunc ;==>_DlgProc Func _DBG_WM_MOVING($hwnd, $uMsg, $wParam, $lParam) If $hwnd = $_DBG_GUI And IsHWnd($_DBG_BUTTONSGUI) Then Local $pos = WinGetPos($hwnd) WinMove($_DBG_BUTTONSGUI, "", $pos[0], $pos[1] + $pos[3]) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_DBG_WM_MOVING Func _DBG_WM_SIZE($hwnd, $message, $wParam, $lParam);fenstergrösse wird verändert Local $posgui = WinGetPos($_DBG_GUI) $_DBG_Window_posold_x = $posgui[0] ;fensterposition merken $_DBG_Window_posold_y = $posgui[1] ;WinMove($hwnd_weiterbutton, "", $pos[0], $pos[1] + $pos[3], 200, 60);buttonposition anpassen WinMove($hwnd_weiterbutton, "", $posgui[0], $posgui[1] + $posgui[3], $posgui[2], 60);fensterposition anpassen WinMove($_DBG_GUI, "", $posgui[0], $posgui[1], $posgui[2], $posgui[3]);fensterposition anpassen _WinAPI_SetWindowPos($_DBG_buttonID, 0, 0, 0, $posgui[2], 60, 0x0020);buttonpos im fenster resze EndFunc ;==>_DBG_WM_SIZE You can use also different inline assembler UDFs, e.g. Extended Flat Assembler (by Beege) or the originaly by Ward The Embedded Flat Assembler (FASM) UDF Without the help of AndyG and Eukalyptus I wouldn't be able to create ASM code - many thanks!!! Many thanks dudes - you rock! I'm a novice in assembler coding - please don't blame me. Feel free to post your snippets here! Categories String _ASM_StringLFCharCount (counts the line feeds within a string) _ASM_StringReplaceWChar (replaces a unicode char within a string) _StringReverse / _StringReverse2 (reverse a string coded by AndyG) Graphic _ASM_DrawRectFilled (draws a filled rectangle) _ASM_ImageInvert (inverts (negative) an image) _ASM_BitmapCreateBitmapWithAlpha (merges an image with an alpha blend image) _ASM_ImageCreateNegativeMMX (inverts (negative) an image using MMX) _ASM_DrawLineUsingGDIPlus (draws a line using the GDIPlus lib) _ASM_BitCompareBitmapsMMX (bitwise bitmap compare) _ASM_BitmapGetAverageColorValue / _ASM64_BitmapGetAverageColorValue.au3 (gets the average color of a bitmap)1 point
-
This script will also retrieve the resource from the compiled script and write it to another file: #AutoIt3Wrapper_Res_File_Add=test.png,png #include <WinAPIRes.au3> #include <WinAPIInternals.au3> Local $bBytes = _GetResourceAsBytes("PNG") If @error Then ; Resource not found Else FileDelete("testOut.png") FileWrite("testOut.png", $bBytes) EndIf Func _GetResourceAsBytes($sResName, $seq=1) Local $hMod = _WinAPI_GetModuleHandle(Null) Local $hRes = _WinAPI_FindResource($hMod, $sResName, $seq) If @error Or Not $hRes Then Return SetError(1, 0, 0) Local $dSize = _WinAPI_SizeOfResource($hMod, $hRes) If @error Or Not $dSize Then Return SetError(2, 0, 0) Local $hLoad = _WinAPI_LoadResource($hMod, $hRes) If @error Or Not $hLoad Then Return SetError(3, 0, 0) Local $pData = _WinAPI_LockResource($hLoad) If @error Or Not $pData Then Return SetError(4, 0, 0) Local $tBuffer = DllStructCreate("byte[" & $dSize & "]") _WinAPI_MoveMemory(DllStructGetPtr($tBuffer), $pData, $dSize) Return DllStructGetData($tBuffer, 1) EndFunc Jos1 point
-
1 point
-
I have been searching for a while for a script to toggle the default sound device, so that i can easily switch between Speakers and Headphones. Some added a tray icon and keep running on background, some will call up the control panel briefly, while some need to call nircmd externally. I ended up gathered some cool scripts (sorry, i failed to recall the original source) and modified for my own taste. It will get the current default playback device, and then set to the next one. It will print an icon on the screen, and then will just exit. Good to use with shortcut key on keyboards, etc. Feel free to try. I was able to retrieve the actual icons info but found it not satisfactory to draw the icon using GUI. So, I simply use SplashText with Webdings font. ;========================================================== ; Set Default Playback Device ; to the next available one ;========================================================== #NoTrayIcon #include <WinAPI.au3> #include <Constants.au3> Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}" Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}" Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr);" Global Const $sCLSID_CPolicyConfigClient = "{870af99c-171d-4f9e-af0d-e63df40c2bc9}" Global Const $sIID_IPolicyConfig = "{f8679f50-850a-41cf-9c72-430f290290c8}" Global Const $tagIPolicyConfig = "GetMixFormat hresult(wstr;ptr*);" & _ "GetDeviceFormat hresult(wstr;int;ptr*);" & _ "ResetDeviceFormat hresult(wstr);" & _ "SetDeviceFormat hresult(wstr;ptr;ptr);" & _ "GetProcessingPeriod hresult(wstr;int;int64*;int64*);" & _ "SetProcessingPeriod hresult(wstr;int64*);" & _ "GetShareMode hresult(wstr;ptr);" & _ "SetShareMode hresult(wstr;ptr);" & _ "GetPropertyValue hresult(wstr;struct;variant*);" & _ "SetPropertyValue hresult(wstr;struct;variant*);" & _ "SetDefaultEndpoint hresult(wstr;int);" & _ "SetEndpointVisibility hresult(wstr;int);" Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" Global Const $tagIMMDevice = "Activate hresult(ptr;dword;variant*;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(ptr*);" & _ "GetState hresult(dword*);" Global Const $IID_IMMDeviceCollection = "{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}" Global Const $tagIMMDeviceCollection = "GetCount hresult(uint*);" & _ "Item hresult(uint;ptr*)" Global Const $IID_IPropertyStore = "{886d8eeb-8cf2-4446-8d02-cdba1dbdcf99}" Global Const $tagIPropertyStore = "GetCount hresult(dword*);" & _ "GetAt hresult(dword;ptr*);" & _ "GetValue hresult(ptr;variant*);" & _ "SetValue hresult(ptr;variant);" & _ "Commit hresult();" Global Const $sPKEY_Device_FriendlyName = "{a45c254e-df1c-4efd-8020-67d146a850e0} 2" Global Const $sPKEY_Device_Icon = "{259abffc-50a7-47ce-af08-68c9a7d73366} 12" Global Const $STGM_READ = 0 Global Const $DEVICE_STATE_ACTIVE = 0x00000001 Global Const $S_OK = 0 Global Const $E_INVALIDARG = 0x80070057 Global Const $eRender = 0 Global Const $eCapture = 1 Global Const $eAll = 2 Global Const $EDataFlow_enum_count = 3 Global Const $eConsole = 0 Global Const $eMultimedia = 1 Global Const $eCommunications = 2 Global Const $ERole_enum_count = 3 ;========================================================== If @OSVersion <> "WIN_7" Then Exit ; God knows what $tagIPolicyConfig is for other systems ; First generate array filled with devices data Global $aArray = _EnumerateDevices() ; FY: Get default device id Global $sDefID = _GetDefaultDevice() ; Set next device as default device $nDev = UBound($aArray, 2) ; no. of devices For $i = 0 to $nDev -1 If $aArray[0][$i]=$sDefID Then $sDev=$i+1 Next If $sDev >= $nDev Then $sDev = 0 _SwitchToDevice($aArray[0][$sDev]) $logo = "U" if $aArray[1][$sDev] = "Headphones" Then $logo=chr(178) $xTT = @DesktopWidth/2-50 $yTT = @DesktopHeight/2-70 ToolTip(" ", $xTT, $yTT, $aArray[1][$sDev],0) SplashTextOn("",$logo, 100, 100, -1, -1, 33, "Webdings", 80) Sleep(2000) SplashOff() Exit ; THE END Func _GetDefaultDevice() ; Error monitoring Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") #forceref $oErrorHandler ; MMDeviceEnumerator Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) Local $pDefaultDevice $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDefaultDevice) Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $IID_IMMDevice, $tagIMMDevice) Local $pDefID, $sDefId $oDefaultDevice.GetId($pDefID) $sDefId = DllStructGetData(DllStructCreate("wchar ID[" & _WinAPI_PtrStringLenW($pDefID) & "]", $pDefID), "ID") _WinAPI_CoTaskMemFree($pDefID) Return $sDefID EndFunc ;==>_GetDefaultDevice Func _EnumerateDevices() ; Error monitoring Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") #forceref $oErrorHandler ; Creae MMDeviceEnumerator object Local $oEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) ; Get collection out of it Local $pCollection $oEnumerator.EnumAudioEndpoints($eRender, $DEVICE_STATE_ACTIVE, $pCollection) ; Turn it into object Local $oCollection = ObjCreateInterface($pCollection, $IID_IMMDeviceCollection, $tagIMMDeviceCollection) ; Check the number of devices in collection Local $iCount $oCollection.GetCount($iCount) ; Array for out Local $aArray[2][$iCount] Local $pEndpoint, $oEndpoint Local $pID, $sId, $pProps, $oProps Local $sName Local $tPKEY_Device_FriendlyName = _WinAPI_PKEYFromString($sPKEY_Device_FriendlyName) Local $tPKEY_Device_Icon = _WinAPI_PKEYFromString($sPKEY_Device_Icon) ; Actual enumeration For $i = 0 To $iCount - 1 ; Item at "i" index is audio endpoint device $oCollection.Item($i, $pEndpoint) $oEndpoint = ObjCreateInterface($pEndpoint, $IID_IMMDevice, $tagIMMDevice) ; Collect ID $oEndpoint.GetId($pID) $sId = DllStructGetData(DllStructCreate("wchar ID[" & _WinAPI_PtrStringLenW($pID) & "]", $pID), "ID") _WinAPI_CoTaskMemFree($pID) $aArray[0][$i] = $sId ; PropertyStore stores properties, lol $oEndpoint.OpenPropertyStore($STGM_READ, $pProps) $oProps = ObjCreateInterface($pProps, $IID_IPropertyStore, $tagIPropertyStore) ; Collect FriendlyName property $sName = 0 $sIcon = 0 $oProps.GetValue(DllStructGetPtr($tPKEY_Device_FriendlyName), $sName) $oProps.GetValue(DllStructGetPtr($tPKEY_Device_Icon), $sIcon) $aArray[1][$i] = $sName Next Return $aArray EndFunc ;==>_EnumerateDevices Func _SwitchToDevice($sId) Local $oPolicyConfig = ObjCreateInterface($sCLSID_CPolicyConfigClient, $sIID_IPolicyConfig, $tagIPolicyConfig) Local $hResult $hResult = $oPolicyConfig.SetDefaultEndpoint($sId, $eConsole) If $hResult = $S_OK Then $hResult = $oPolicyConfig.SetDefaultEndpoint($sId, $eCommunications) Return $hResult = $S_OK EndFunc ;==>_SwitchToDevice Func _WinAPI_PKEYFromString($sPKEY, $pID = Default) Local $tPKEY = DllStructCreate("byte GUID[16]; dword PID;") DllCall("propsys.dll", "long", "PSPropertyKeyFromString", "wstr", $sPKEY, "ptr", DllStructGetPtr($tPKEY)) If @error Then ; alternative for unsupported systems Local $tGUID = _WinAPI_GUIDFromString($sPKEY) If Not @error Then DllStructSetData($tPKEY, "GUID", DllStructGetData(DllStructCreate("byte Data[16]", DllStructGetPtr($tGUID)), 1)) EndIf DllStructSetData($tPKEY, "PID", Number(StringRegExpReplace($sPKEY, ".*?}", ""))) EndIf If $pID <> Default Then DllStructSetData($tPKEY, "PID", $pID) Return $tPKEY EndFunc ;==>_WinAPI_PKEYFromString Func _WinAPI_PtrStringLenW($pString) Local $aCall = DllCall("kernel32.dll", "dword", "lstrlenW", "ptr", $pString) If @error Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc ;==>_WinAPI_PtrStringLenW Func _WinAPI_CoTaskMemFree($pMem) DllCall("ole32.dll", "none", "CoTaskMemFree", "ptr", $pMem) If @error Then Return SetError(1, 0, False) Return True EndFunc ;==>_WinAPI_CoTaskMemFree Func _ErrFunc($oError) ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF) EndFunc ;==>_ErrFunc1 point
-
GUI with no minimize of maximize
BlackLumiere reacted to Melba23 for a topic
SoulA, This is one way: #include <WindowsConstants.au3> GUICreate("Test", 500, 500, -1, -1, $WS_SYSMENU) GUISetState() While 1 If GUIGetMsg() = -3 Then Exit WEnd M231 point