SharpDressedMan Posted November 12, 2018 Posted November 12, 2018 (edited) Hello, Is there any way to check for validity of a pointer to a DllStruct ? In the above code, a DllStruct is created from an invalid pointer. How to prevent from doing this ? local $tStruct = DllStructCreate("int i") DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? $tStruct = DllStructCreate("int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct)) ; displays '1' : tStruct is assumed as a valid DllStruct object, which is not Thanks for help Edited November 12, 2018 by SharpDressedMan
water Posted November 12, 2018 Posted November 12, 2018 Check the help file and you will see that the function returns useful information in case of an error. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
SharpDressedMan Posted November 12, 2018 Author Posted November 12, 2018 53 minutes ago, water said: Check the help file and you will see that the function returns useful information in case of an error. Thanks for answer, Unfortunately, there is no error returned. The last call to DllStructCreate (with invalid pointer) does succeed despite of the invalid pointer passed. I updated the code snippet above to state this.
Earthshine Posted November 12, 2018 Posted November 12, 2018 (edited) the pointer is an address in memory so you tell me how to validate that address. Edited November 12, 2018 by Earthshine My resources are limited. You must ask the right questions
SharpDressedMan Posted November 12, 2018 Author Posted November 12, 2018 (edited) 3 hours ago, Earthshine said: the pointer is an address in memory so you tell me how to validate that address. A **raw** pointer is an address in memory. I don't know what kind of pointer DllStructGetPtr returns. If it's raw, then you're right: no way to check for validity, Howver, AutoIt seams to manage memory using some kinds of shared pointers, so one could expect that DllStructGetPtr returns a weak pointer (which allows to check for validity). Edited November 12, 2018 by SharpDressedMan
Earthshine Posted November 12, 2018 Posted November 12, 2018 What is a weak pointer? My resources are limited. You must ask the right questions
SharpDressedMan Posted November 12, 2018 Author Posted November 12, 2018 1 hour ago, Earthshine said: What is a weak pointer? it is an object that includes a reference to a resource managed by a shared pointer. See C++11 implementation for example: https://en.cppreference.com/w/cpp/memory/weak_ptr
Earthshine Posted November 12, 2018 Posted November 12, 2018 (edited) look, you are going to have to look at the object it points to and perhaps write validation code using what you know about the object-- if it's to be done. so have a look at this https://msdn.microsoft.com/en-us/library/hh279674.aspx yeah, once the resource is allocated, the smart pointer owns the raw, so probably same thing. other than testing for not being null, what else could you do but interrogate the object it's pointing to.... Edited November 12, 2018 by Earthshine My resources are limited. You must ask the right questions
Bilgus Posted November 13, 2018 Posted November 13, 2018 (edited) Pointers are dangerous they allow you to shoot your feet.. some things are mentioned here: The only way I can think to stop the situation is something like this.. local $tStruct = DllStructCreate("int sentinel;int i") DllStructSetData($tStruct, "sentinel", 0xBADE1F) DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? local $tStruct2 = DllStructCreate("int sentinel;int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct2) And (DllStructGetData($tStruct2, "sentinel") = 0xBADE1F)) Edited November 13, 2018 by Bilgus
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