mLipok Posted November 17, 2023 Share Posted November 17, 2023 I have some inaccuracies in my understanding of several issues. I had a problem that made me wonder what the difference is between IsPtr() and IsHwnd() I modified the example from the documentation for the IsPtr() function as follows: #include <MsgBoxConstants.au3> Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ConsoleWrite("#" & @ScriptLineNumber & " - " & IsHWnd($hWnd) & @CRLF) ConsoleWrite("#" & @ScriptLineNumber & " - " & IsPtr($hWnd) & @CRLF) ConsoleWrite("#" & @ScriptLineNumber & " - " & VarGetType($hWnd) & @CRLF) ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ;==>Example I would like to ask why both functions IsPtr() IsHwnd() return a positive result ? I assumed these were two different things (Handle and Pointer). Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Andreik Posted November 17, 2023 Share Posted November 17, 2023 I suppose you want to know the difference between handles and pointers not strictly between IsPtr() and IsHWnd() which are functions used to identify if a variable is a pointer or a handle, right? In short terms a handle it's a reference to an object in memory. This reference might be a number of different things but usually it's an integer index specific to a resource while a pointer it's variable that stores the address of another variable. But we must keep in mind that pointers are not just ordinary variables because they have data types and allows operations specific to pointers. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Danp2 Posted November 17, 2023 Share Posted November 17, 2023 From the online help -- Quote Pointer types store a memory address which is 32bits or 64bits depending on if the 32bit or 64-bit version of AutoIt is used. They are converted to hexadecimal representation when stored in a string variable. Window handles (HWnd) as returned from WinGetHandle() are a pointer type. I was surprised to read that Window handles are a pointer type. I've always thought of handles as "a pointer to a pointer". Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Solution Nine Posted November 17, 2023 Solution Share Posted November 17, 2023 IsHwnd requires that the window exist. While IsPtr not. That's the main difference. See : #include <MsgBoxConstants.au3> Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) WinKill($hWnd) ConsoleWrite("#" & @ScriptLineNumber & " - " & IsHWnd($hWnd) & @CRLF) ConsoleWrite("#" & @ScriptLineNumber & " - " & IsPtr($hWnd) & @CRLF) ConsoleWrite("#" & @ScriptLineNumber & " - " & VarGetType($hWnd) & @CRLF) EndFunc ;==>Example mLipok 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
UEZ Posted November 17, 2023 Share Posted November 17, 2023 (edited) Source ChatGPT: Quote Pointers and handles are both concepts used in computer programming, but they are typically associated with different programming paradigms and have some differences in their usage. 1. **Pointers:** - **Definition:** A pointer is a variable that stores the memory address of another variable. In other words, it "points" to the location in memory where the actual data is stored. - **Usage:** Pointers are commonly used in low-level programming languages like C and C++. They provide direct access to memory addresses, allowing for more fine-grained control over memory management. - **Dereferencing:** To access the value pointed to by a pointer, you need to dereference it using the `*` operator in languages like C or C++. ```c int x = 10; int *ptr = &x; // ptr points to the memory address of x int value = *ptr; // Dereferencing ptr to get the value at the memory address it points to ``` - **Memory Management:** Pointers require manual memory management, meaning the programmer is responsible for allocating and freeing memory. 2. **Handles:** - **Definition:** A handle is an abstract reference or identifier used to access an object or resource. Unlike pointers, handles don't directly represent memory addresses; instead, they serve as a way to indirectly reference an object. - **Usage:** Handles are often used in high-level programming languages, especially those with automatic memory management (garbage collection), such as Java or C#. - **Abstraction:** Handles provide a level of abstraction, allowing the underlying system to manage memory without direct intervention from the programmer. ```java // Java example using handles (references) String str = "Hello, World!"; ``` - **Automatic Memory Management:** Handles are associated with automatic memory management systems, where the runtime environment takes care of memory allocation and deallocation. In summary, while both pointers and handles are used to reference objects or data, pointers are more direct and low-level, involving memory addresses and manual memory management. Handles, on the other hand, are often higher-level abstractions used in languages with automatic memory management, providing a layer of indirection between the programmer and the actual memory addresses. Edited November 17, 2023 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
mLipok Posted November 19, 2023 Author Share Posted November 19, 2023 (edited) btw. here is some more examples: #include <Array.au3> Example() Func Example() ; Retrieve a list of window handles using a regular expression. The regular expression looks for titles that contain the word SciTE or Internet Explorer. Local $aWinList = WinList("[REGEXPTITLE:(?i)(.*SciTE.*|.*Internet Explorer.*)]") For $i=1 To $aWinList[0][0] ConsoleWrite("- " & $aWinList[$i][1] & ' TYPE=' & VarGetType($aWinList[$i][1]) & @CRLF) Next Local $hWND = WinGetHandle("[REGEXPTITLE:(?i)(.*SciTE.*|.*Internet Explorer.*)]") ;~ Local $hWND = WinWait("[REGEXPTITLE:(?i)(.*SciTE.*|.*Internet Explorer.*)]") ConsoleWrite("> " & $hWND & ' TYPE=' & VarGetType($hWND) & @CRLF) ConsoleWrite("> " & ' IsHWnd=' & IsHWnd($hWND) & @CRLF) ConsoleWrite("> " & ' IsPtr=' & IsPtr($hWND) & @CRLF) _ArrayDisplay($aWinList) EndFunc ;==>Example and of course from HelpFile "VarGetType.au3": expandcollapse popup#include <MsgBoxConstants.au3> Local $aArray[2] = [1, "Example"] Local $mMap[] Local $dBinary = Binary("0x00204060") Local $bBoolean = False Local $pPtr = Ptr(-1) Local $hWnd = WinGetHandle(AutoItWinGetTitle()) Local $iInt = 1 Local $fFloat = 2.0 Local $oObject = ObjCreate("Scripting.Dictionary") Local $sString = "Some text" Local $tStruct = DllStructCreate("wchar[256]") Local $vKeyword = Default Local $fuFunc = ConsoleWrite Local $fuUserFunc = Test MsgBox($MB_SYSTEMMODAL, "", _ "Variable Types" & @CRLF & @CRLF & _ "$aArray : " & @TAB & @TAB & VarGetType($aArray) & " variable type." & @CRLF & _ "$mMap : " & @TAB & @TAB & VarGetType($mMap) & " variable type." & @CRLF & _ "$dBinary : " & @TAB & @TAB & VarGetType($dBinary) & " variable type." & @CRLF & _ "$bBoolean : " & @TAB & VarGetType($bBoolean) & " variable type." & @CRLF & _ "$pPtr : " & @TAB & @TAB & VarGetType($pPtr) & " variable type." & @CRLF & _ "$hWnd : " & @TAB & @TAB & VarGetType($hWnd) & " variable type." & @CRLF & _ "$iInt : " & @TAB & @TAB & VarGetType($iInt) & " variable type." & @CRLF & _ "$fFloat : " & @TAB & @TAB & VarGetType($fFloat) & " variable type." & @CRLF & _ "$oObject : " & @TAB & VarGetType($oObject) & " variable type." & @CRLF & _ "$sString : " & @TAB & @TAB & VarGetType($sString) & " variable type." & @CRLF & _ "$tStruct : " & @TAB & @TAB & VarGetType($tStruct) & " variable type." & @CRLF & _ "$vKeyword : " & @TAB & VarGetType($vKeyword) & " variable type." & @CRLF & _ "MsgBox : " & @TAB & @TAB & VarGetType(MsgBox) & " variable type." & @CRLF & _ "$fuFunc : " & @TAB & @TAB & VarGetType($fuFunc) & " variable type." & @CRLF & _ "Func 'Test' : " & @TAB & VarGetType(Test) & " variable type." & @CRLF & _ "$fuUserFunc : " & @TAB & VarGetType($fuUserFunc) & " variable type.") Func Test() EndFunc ;==>Test Both VarGetType($hWnd) shows PTR as a result. Is there any case when VarGetType($hWnd) will return HWND ? Edited November 19, 2023 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
argumentum Posted November 19, 2023 Share Posted November 19, 2023 (edited) seems like not but it can differentiated: #include <MsgBoxConstants.au3> Local $pPtr = Ptr(-1) Local $hWnd = WinGetHandle(AutoItWinGetTitle()) MsgBox($MB_SYSTEMMODAL, "", _ "$pPtr : " & @TAB & @TAB & VarGetType($pPtr) & ' - ' & IsHWnd($pPtr) & ' - ' & IsPtr($pPtr) & " variable type." & @CRLF & _ "$hWnd : " & @TAB & @TAB & VarGetType($hWnd) & ' - ' & IsHWnd($hWnd) & ' - ' & IsPtr($hWnd) & " variable type." & @CRLF ) maybe open a trac and ask to be looked at ? Edited November 19, 2023 by argumentum spelling Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Andreik Posted November 19, 2023 Share Posted November 19, 2023 10 hours ago, mLipok said: Is there any case when VarGetType($hWnd) will return HWND ? Probably not. It's easy to call FindWindowA and you will see that the result of such a call it's in fact a pointer. Anyway IsHWnd() can be used to test the small range of window handles but as I said in a previous comment handles can be a number of different things and it would be more handy to have a function named IsHandle() and maybe set @extended according with the handle type (window, file, etc). When the words fail... music speaks. Link to comment Share on other sites More sharing options...
mLipok Posted November 19, 2023 Author Share Posted November 19, 2023 19 minutes ago, Andreik said: it would be more handy to have a function named IsHandle() and maybe set @extended according with the handle type (window, file, etc). Nice idea. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 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