Popular Post monoceres Posted April 19, 2009 Popular Post Share Posted April 19, 2009 (edited) So I think it's time to publish this little tutorial I have made on using DllCall() and DllStructs. It's not near completion but I think it's a good start at least This tutorial is mostly aimed for people who have never used DllCall() before or have very limited knowledge about it. In the future I will update it with more advanced topics so more advanced users can make use of it too. Well here goes. Dealing_with_Dll.pdf Previous downloads: 31 Suggestions, language corrections and errors in the tutorial is of course welcome. Edited April 19, 2009 by monoceres Morronic, 232showtime, Muhammad_Awais_Sharif and 15 others 15 3 Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
oMBRa Posted April 19, 2009 Share Posted April 19, 2009 Nice tutorial, it has cleared me some things Link to comment Share on other sites More sharing options...
KaFu Posted April 19, 2009 Share Posted April 19, 2009 Nice one, thanks for the clarifications... worth a new row in my signature ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Authenticity Posted April 19, 2009 Share Posted April 19, 2009 (edited) Heh, thank you very much.Page 6:Strings in DllCall()As you should know strings in dlls are in fact arrays of chars, fortunately AutoIt helps us with passing this so all you have to do is to choose “str” or “wstr” and then just put in your string in the paramx param in DllCall(). A very important thing to remember here is that since windows was not fully Unicode until win2000 almost all function that deals with strings is implemented in two versions. They usually have an ‘A’ or a ‘W’ n the end if its name, like this “MyStringFunctionA”, where A stands for ANSI and W stands for wide char, aka as Unicode.Maybe you've meant in? but I think in is not correct at sounds more correct in my opinion. And if -> of?Page 9:The first thing you’ll probably notice is the type WORD, this type is not specified in AutoIt so you will have find out what Microsoft means with WORD, a quick googling for “WORD typedef” turns out that WORD is actually an unsigned 16 bit integer aka as “ushort” in AutoIt (check the help file entry for DllCall). So the complete translation of the struct (and the simple call) is as follow:(\ /)(o O)('')('') Edited April 19, 2009 by Authenticity Link to comment Share on other sites More sharing options...
monoceres Posted April 19, 2009 Author Share Posted April 19, 2009 Thanks for the feedback @Authenticity Well yeah, those were stupid mistakes, thanks for finding them First post updated. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
James Posted June 21, 2009 Share Posted June 21, 2009 Awesome!Some mistakes I found:Windows is commonly spelt as "windows""msdn" on page 2 should be "MSDN"The tips for the first tasks were insignificant to the actual functions Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
BrettF Posted June 21, 2009 Share Posted June 21, 2009 Oh how did I miss this! Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
rajeshontheweb Posted June 21, 2009 Share Posted June 21, 2009 thanks a lot for the effort!!! sure this will give a bright way into dll stuff for first step learners. thanks again. Started late is much better than having never started it!!!!Failure is another step towards success. I've been messing around with: Adding Entry to 'Hosts'File Information Lister (Logger)Yet Another AutoIT Error Handler Yet Another AutoIT Error Handler & Debugger Control your App's TaskBar Button YCurrency Ticker (Latest Release : 16 Apr 2009)_WinInetInternetCheckConnection UDF Symantec Definitions Lister UDF _GetLocalIPAddresses UDF UDF to get Special Folder Information WMI_NetworkAdapterConfiguration2Array WMI_CDRomDriveCapabilities _ScriptExists - Check if your au3 script is running!! Uninstaller UDF Get Version for your application (at script level or compiled stage) Uninstaller Pro - faster alternative to windows application removal applet Link to comment Share on other sites More sharing options...
Zedna Posted June 21, 2009 Share Posted June 21, 2009 Nice tutorial!I just looked at it quickly.I have found mistake on page 6 at MessageBox:the code to use the ASCII version insteadshould bethe code to use the ANSI version instead Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
enaiman Posted June 21, 2009 Share Posted June 21, 2009 Wow - I feel the same as BrettF ... how did I miss this? Very nice monoceres - thanks for this wonderful tutorial (been lazy enough to not learn about dll's before ) Keep up the good work SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
dantay9 Posted June 21, 2009 Share Posted June 21, 2009 Great tutorial. I haven't really looked into dlls very much because I was too lazy, but now I will because all of the information is in one place. Link to comment Share on other sites More sharing options...
monoceres Posted June 22, 2009 Author Share Posted June 22, 2009 Thanks again! @James & Zedna I correct it when I have time Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Andreik Posted June 22, 2009 Share Posted June 22, 2009 Good tutorial. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 22, 2009 Share Posted June 22, 2009 Excellent idea and a lot of good work in there. I've learned several new things already. I don't think this is true, however (Page 4): This is the exact same function that is being called when you write Sleep(100) in AutoIt, its just that AutoIt acts a layer between you and the function. The reason I don't think so: Sleep can be interrupted: HotKeySet("{ESC}", "_ESC") Sleep(10000) MsgBox(64, "Timeout", "Quitting due to timeout") Func _ESC() MsgBox(64, "ESC", "Quitting on ESC") Exit EndFunc The DLL Sleep call used cannot be interrupted: HotKeySet("{ESC}", "_ESC") DllCall("kernel32.dll", "none", "Sleep", "dword", 10000) MsgBox(64, "Timeout", "Quitting due to timeout") Func _ESC() MsgBox(64, "ESC", "Quitting on ESC") Exit EndFunc Still good stuff, because I wouldn't have tried that without your tutorial's prompting. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 22, 2009 Share Posted June 22, 2009 (edited) @PsaltyDSAutoIt doesn't do one large sleep, but multiple small sleeps that equal the value in Sleep(). A more fair comparison would have been:HotKeySet("{ESC}", "_ESC") For $X = 0 To 100 DllCall("kernel32.dll", "none", "Sleep", "dword", 100) Next MsgBox(64, "Timeout", "Quitting due to timeout") Func _ESC() MsgBox(64, "ESC", "Quitting on ESC") Exit EndFuncNote that I only guessed the numbers, but this makes it interruptable and supports Monoceres claims.Edit: Look at THIS to see what i am rambling about Edited June 22, 2009 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 22, 2009 Share Posted June 22, 2009 (edited) Even more fun! Made this after checking out LockWorkStation because of your DLL tutorial: Get notification when session is locked and unlocked: expandcollapse popupGlobal Const $NOTIFY_FOR_THIS_SESSION = 0x0 Global Const $NOTIFY_FOR_ALL_SESSIONS = 0x1 Global Const $WM_WTSSESSION_CHANGE = 0x2B1 Global Const $WTS_CONSOLE_CONNECT = 0x1 Global Const $WTS_CONSOLE_DISCONNECT = 0x2 Global Const $WTS_REMOTE_CONNECT = 0x3 Global Const $WTS_REMOTE_DISCONNECT = 0x4 Global Const $WTS_SESSION_LOGON = 0x5 Global Const $WTS_SESSION_LOGOFF = 0x6 Global Const $WTS_SESSION_LOCK = 0x7 Global Const $WTS_SESSION_UNLOCK = 0x8 Global Const $WTS_SESSION_REMOTE_CONTROL = 0x9 Global $hGUI = GUICreate("Message Sink", 400, 600); GUI to receive notification Global $sMsg = "$hGUI = " & $hGUI & @CRLF Global $ctrlEdit = GUICtrlCreateEdit($sMsg, 10, 10, 380, 580) GUISetState() GUIRegisterMsg($WM_WTSSESSION_CHANGE, "_WM_WTSSESSION_CHANGE") DllCall("Wtsapi32.dll", "int", "WTSRegisterSessionNotification", "hwnd", $hGUI, "dword", $NOTIFY_FOR_THIS_SESSION) DllCall("Kernel32.dll", "none", "Sleep", "dword", 1000) DllCall("User32.dll", "int", "LockWorkStation") While 1 If GUIGetMsg() = -3 Then ExitLoop WEnd DllCall("Wtsapi32.dll", "int", "WTSUnRegisterSessionNotification", "hwnd", $hGUI) Func _WM_WTSSESSION_CHANGE($hWnd, $iMsgID, $wParam, $lParam) $sMsg &= @CRLF & @HOUR & ":" & @Min & ":" & @SEC & " = " Switch $wParam Case $WTS_CONSOLE_CONNECT $sMsg &= "A session was connected to the console terminal." Case $WTS_CONSOLE_DISCONNECT $sMsg &= "A session was disconnected from the console terminal." Case $WTS_REMOTE_CONNECT $sMsg &= "A session was connected to the remote terminal." Case $WTS_REMOTE_DISCONNECT $sMsg &= "A session was disconnected from the remote terminal." Case $WTS_SESSION_LOGON $sMsg &= "A user has logged on to the session." Case $WTS_SESSION_LOGOFF $sMsg &= "A user has logged off the session." Case $WTS_SESSION_LOCK $sMsg &= "A session has been locked." Case $WTS_SESSION_UNLOCK $sMsg &= "A session has been unlocked." Case $WTS_SESSION_REMOTE_CONTROL $sMsg &= "A session has changed its remote controlled status." EndSwitch $sMsg &= @CRLF & "$hWnd = " & $hWnd & @CRLF & _ "$iMsgID = 0x" & Hex($iMsgID, 8) & @CRLF & _ "$wParam = " & $wParam & @CRLF & _ "$lParam = " & $lParam & @CRLF ControlSetText($hGUI, "", $ctrlEdit, $sMsg) EndFunc Thank you, master monoceres, for my DLL-fu grows stronger! There must be great Chi in sitting around eating cereal in your underwear! Edited June 22, 2009 by PsaltyDS MrKm 1 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Zedna Posted June 22, 2009 Share Posted June 22, 2009 @PsaltyDSThere are older Autoit's sources so you may look at Sleep implementationhttp://www.autoitscript.com/autoit3/files/...-v3.1.0-src.exe Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 22, 2009 Share Posted June 22, 2009 (edited) @PsaltyDSThere are older Autoit's sources so you may look at Sleep implementationhttp://www.autoitscript.com/autoit3/files/...-v3.1.0-src.exeThanks for the tip, very interesting. Inside Utility.cpp, the util_sleep() function loops "::sleep(0);" until another counter detects timeout. I assume the double colon "::" makes a library reference to the C++ sleep() function. Is that the same thing as calling the Kernel32.dll version of sleep()?Another difference I notice is the DLL sleep() accepts -1 as INFINITE (never timeout), but the AutoIt function just ignores any timeout < 0. Edit: Typo. Edited June 22, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 22, 2009 Share Posted June 22, 2009 Why would you want to never timeout? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 22, 2009 Share Posted June 22, 2009 Why would you want to never timeout?I don't know enough C++ to say, but I get the impression there are other ways to get the thread to continue besides a timeout. Perhaps registered events or callbacks? When I said "cannot be interrupted" earlier, I meant in AutoIt. It wouldn't be surprising to have more options in C++.The reference MSDN article mentions SleepEx() for just such usage. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now