maniootek Posted May 1, 2020 Share Posted May 1, 2020 (edited) Just as topic says - Is there any chance to assign variable to object property with string representing an expression? I tried: Execute('$oMyObject.Name = "Some name"') also Assign("$oMyObject.Name", "Some name", 4) but does not work Any idea? Edit: I just found similar thread but from 2012 and it looks like it's not possible with AutoIt that time. Can someone confirm if anything changed? Edited May 1, 2020 by maniootek Link to comment Share on other sites More sharing options...
water Posted May 1, 2020 Share Posted May 1, 2020 Didn't find a way to do it with the property name in a variable. Doesn't seem to be possible. maniootek 1 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 Link to comment Share on other sites More sharing options...
Gianni Posted May 1, 2020 Share Posted May 1, 2020 ... have a look here: Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
water Posted May 1, 2020 Share Posted May 1, 2020 I didn't implement this solution in my code because I do not use code I do/can not fully understand. I wouldn't be able to debug such code if the need arises in the near or far future. So I took the long and winding road 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 Link to comment Share on other sites More sharing options...
Gianni Posted May 1, 2020 Share Posted May 1, 2020 (edited) A simpler way, if it's okay for you to set a property value by passing "strings" to a function instead of using a single string in an Execute () statement, then you can use a "magic" way provided by a magical girl, @trancexx, published at this link: here I simply wrapped his magic potion within this function: expandcollapse popupFunc _SetProperty($oObj, $sProperty, $vData) ; by Trancexx ; https://www.autoitscript.com/forum/topic/200129-set-object-properties-with-propertyname-and-value-taken-from-an-array/?do=findComment&comment=1436379 ; Some constants used in code Const $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" Const $tagIDispatch = $tagIUnknown & _ "GetTypeInfoCount hresult(dword*);" & _ "GetTypeInfo hresult(dword;dword;ptr*);" & _ "GetIDsOfNames hresult(struct*;struct*;dword;dword;struct*);" & _ "Invoke hresult(uint;struct*;dword;word;struct*;struct*;ptr;uint*);" Const $DISPID_PROPERTYPUT = -3 Const $DISPATCH_PROPERTYPUT = 4 Const $LOCALE_SYSTEM_DEFAULT = 0x800 Const $tIID_NULL = DllStructCreate("byte[16]") Const $tagDISPPARAMS = "ptr rgvarg;ptr rgdispidNamedArgs;uint cArgs;uint cNamedArgs;" Const $VT_I4 = 3 Const $tVARIANT = "word vt;word r1;word r2;word r3;ptr data; ptr" Const $sIID_IDispatch = "{00020400-0000-0000-C000-000000000046}" ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; Superposed object on top of the original one Local $oObjMy = ObjCreateInterface($oObj, $sIID_IDispatch, $tagIDispatch, False) ; Collect ID number of the function/property/method, whatever $tDisp = DllStructCreate("dword") $tName = DllStructCreate("ptr") $tN = DllStructCreate("wchar[" & StringLen($sProperty) + 1 & "]") DllStructSetData($tN, 1, $sProperty) DllStructSetData($tName, 1, DllStructGetPtr($tN)) $oObjMy.GetIDsOfNames($tIID_NULL, $tName, 1, $LOCALE_SYSTEM_DEFAULT, $tDisp) ; Tadaaa! $iDispId = DllStructGetData($tDisp, 1) ; Now build disp parameters $tDISPPARAMS = DllStructCreate($tagDISPPARAMS) $tDISPPARAMS.cNamedArgs = 1 $tDispidNamed = DllStructCreate("uint") DllStructSetData($tDispidNamed, 1, $DISPID_PROPERTYPUT) $tDISPPARAMS.rgdispidNamedArgs = DllStructGetPtr($tDispidNamed) $tDISPPARAMS.cArgs = 1 $tVar = DllStructCreate($tVARIANT) $tDISPPARAMS.rgvarg = DllStructGetPtr($tVar) ; Set desired value $tVar.vt = $VT_I4 $tVar.data = $vData ; And call it $iRet = $oObjMy.Invoke($iDispId, $tIID_NULL, 0x800, $DISPATCH_PROPERTYPUT, $tDISPPARAMS, 0, 0, 0) Return (Hex($iRet, 8)) ; ConsoleWrite(">>> Returned hresult = " & Hex($iRet, 8) & @CRLF) ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc ;==>_SetProperty here an example of use: https://www.autoitscript.com/forum/topic/200129-set-object-properties-with-propertyname-and-value-taken-from-an-array/?do=findComment&comment=1436386 Edited May 1, 2020 by Chimp FrancescoDiMuro 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Popular Post trancexx Posted May 2, 2020 Popular Post Share Posted May 2, 2020 You could also use some sort of wrapper object that allows something like that, on top of the original one. This method would be the simplest to use. Unfortunately no one ever shared the code that would do that because writing sensible implementation requires extended knowledge of the memory management, COM Idispatch handling and whatnot. I remember one user writing it in AutoIt but it has different issues. I would do it like this (added __propget__, __propset__ and __call__ for every object): ObjectExtend.au3 expandcollapse popup#include-once ; ExtendObj.au3 ;.......script written by trancexx (trancexx at yahoo dot com) - yea it's PayPal address too Func ObjectExtend($oObject) ; This function adds three methods to original $oObject: __propget__, __propset__ and __call__ ; Resulting object doesn't require any special memory managment. It frees and deallocates itself when reference count reaches 0, like any other object in AutoIt Local $tIntfc If @AutoItX64 Then $tIntfc = DllStructCreate("ptr Object;ptr Original;ulong refCount;ptr pFree;ptr pQueryInterface;ptr pAddRef;ptr pRelease;ptr pGetTypeInfoCount;ptr pGetTypeInfo;ptr pGetIDsOfNames;ptr pInvoke;byte QueryInterface[12];byte AddRef[36];byte Release[44];byte GetTypeInfoCount[12];byte GetTypeInfo[12];byte GetIDsOfNames[148];byte Invoke[536];", __Extend_VirtualAlloc(0, 888, 0x1000, 64)) DllStructSetData($tIntfc, "QueryInterface", "0x488B4908488B0148FF20") DllStructSetData($tIntfc, "AddRef", "0x40534883EC20488BD9488B4908488B01FF50088B4310FFC08943104883C4205BC3") DllStructSetData($tIntfc, "Release", "0xFF4910514883EC20488B4908488B11FF52104883C420598B411085C0750B31D241B800800000FF6118C3") DllStructSetData($tIntfc, "GetTypeInfoCount", "0x488B4908488B0148FF6018") DllStructSetData($tIntfc, "GetTypeInfo", "0x488B4908488B0148FF6020") DllStructSetData($tIntfc, "GetIDsOfNames", "0x48895C2408574883EC304C8B5C2468418BF94D85C074544D85DB744F498B1841BA05150000440FB70B4585C9743D4183E1DF456BD221488D5B024503D1440FB70B4585C975E84181FABDAC0A5A74124181FA62ECB77D74094181FA6E12917E750A41F7DA45891333C0EB1B488B4908448BCF8B4424604C895C2428894424204C8B1141FF5228488B5C24404883C4305FC3") DllStructSetData($tIntfc, "Invoke", "0x488BC4488958084889701848897820895010554154415541564157488BEC4883EC60488B5D58418BF9498BF04C8BF181FA92ED6E810F85DD0000008B4310488B4908FFC84C8B11488D1440488B03488D52014C8D04D0488BD6488D4538488944242844894C242041B90100000041FF5228FF4B10488D45F04C8B7D70BA040000004C8B6568448BCF4C8B6D604C8BC64C897C244048894308C7431401000000498B4E084C89642438C745F0FDFFFFFF4C896C2430488B0148895C242866895424208B5538FF50303D030002800F8527010000498B4E08BA080000004C897C2440448BCF4C896424384C8BC64C896C2430488B0148895C242866895424208B5538FF50303D030002800F85EB000000B806000280E9E100000081FA9E13488275518B431033D289553885C0743A488B4908FFC88BD041B9010000004C8B114C8D044501000000488B034C03C2488BD64E8D04C0488D45384889442428897C242041FF52288B5538FF4B1041B802000000EB5181FA4353F5A575448B431085C0748E488B4908FFC88BD041B9010000004C8B114C8D044501000000488B034C03C2488BD64E8D04C0488D45384889442428897C242041FF5228FF4B108B5538440FB74550488B4570448BCF498B4E084889442440488B45684889442438488B45604C8B11488944243048895C24286644894424204C8BC641FF52304C8D5C2460498B5B30498B7340498B7B48498BE3415F415E415D415C5DC3") Else $tIntfc = DllStructCreate("ptr Object;ptr Original;ulong refCount;ptr pFree;ptr pQueryInterface;ptr pAddRef;ptr pRelease;ptr pGetTypeInfoCount;ptr pGetTypeInfo;ptr pGetIDsOfNames;ptr pInvoke;byte QueryInterface[16];byte AddRef[24];byte Release[48];byte GetTypeInfoCount[16];byte GetTypeInfo[16];byte GetIDsOfNames[108];byte Invoke[356];", __Extend_VirtualAlloc(0, 628, 0x1000, 64)) DllStructSetData($tIntfc, "QueryInterface", "0x8B4424048B40048B0889442404FF21") DllStructSetData($tIntfc, "AddRef", "0x8B5424048B4204508B08FF5104FF42088B4208C20400") DllStructSetData($tIntfc, "Release", "0x8B5424048B5204528B12FF52085A5952FF49088B410885C07515680080000050518B510C40803C02C375F901D05052C3") DllStructSetData($tIntfc, "GetTypeInfoCount", "0x8B4424048B40048B0889442404FF610C") DllStructSetData($tIntfc, "GetTypeInfo", "0x8B4424048B40048B0889442404FF6110") DllStructSetData($tIntfc, "GetIDsOfNames", "0x837C24180074498B44240C85C074418B10B8051500000FB70A85C974336BC0218D520283E1DF01C80FB70A85C975EE3DBDAC0A5A740E3D62ECB77D74073D6E12917E750CF7D88B542418890231C0EB168B4424046A0559FF742418E2FA8B4004508B00FF5014C21800") DllStructSetData($tIntfc, "Invoke", "0x8B542408538B5C2408558B6C2418565781FA92ED6E810F85A20000008B7C24288D4424188B730450558B4F088B078B1683C0F86A01C1E10403C150FF74242C56FF5214FF742434FF4F088D442418FF7424348B742424FF742434C7470C01000000576A048947048B43045556FF742434C7442434FDFFFFFF8B0850FF51183D030002800F85D3000000FF7424348B4304FF742434FF7424348B08576A085556FF74243450FF51183D030002800F85AA0000005F5E5DB8060002805BC224008B74242881FA9E134882753B8B7E0833D28954241885FF74248B4B048D442418508B06558B1183C0F86A01C1E70403C750FF74242C51FF52148B542418FF4E08BF02000000EB3A81FA4353F5A5752E8B7E0885FF749E8B4B048D442418508B06558B1183C0F86A01C1E70403C750FF74242C51FF5214FF4E088B5424188B7C2424FF7424348B4304FF742434FF7424348B08565755FF7424345250FF51185F5E5D5BC22400") EndIf DllStructSetData($tIntfc, "Object", DllStructGetPtr($tIntfc, "pQueryInterface")) DllStructSetData($tIntfc, "Original", Ptr($oObject)) DllStructSetData($tIntfc, "refCount", 1) DllStructSetData($tIntfc, "pFree", __Extend_GetProcAddress(__Extend_GetModuleHandle("kernel32.dll"), "VirtualFree")) DllStructSetData($tIntfc, "pQueryInterface", DllStructGetPtr($tIntfc, "QueryInterface")) DllStructSetData($tIntfc, "pAddRef", DllStructGetPtr($tIntfc, "AddRef")) DllStructSetData($tIntfc, "pRelease", DllStructGetPtr($tIntfc, "Release")) DllStructSetData($tIntfc, "pGetTypeInfoCount", DllStructGetPtr($tIntfc, "GetTypeInfoCount")) DllStructSetData($tIntfc, "pGetTypeInfo", DllStructGetPtr($tIntfc, "GetTypeInfo")) DllStructSetData($tIntfc, "pGetIDsOfNames", DllStructGetPtr($tIntfc, "GetIDsOfNames")) DllStructSetData($tIntfc, "pInvoke", DllStructGetPtr($tIntfc, "Invoke")) ; Call AddRef on original object DllCallAddress("ulong", DllStructGetData(DllStructCreate("ptr pQueryInterface;ptr pAddRef;ptr pRelease;", DllStructGetData(DllStructCreate("ptr Object", Ptr($oObject)), 1)), "pAddRef"), "ptr", Ptr($oObject)) Return ObjCreateInterface(DllStructGetPtr($tIntfc), Default, Default, False) EndFunc Func __Extend_VirtualAlloc($pAddress, $iSize, $iAllocationType, $iProtect) Local $aCall = DllCall("kernel32.dll", "ptr", "VirtualAlloc", "ptr", $pAddress, "dword_ptr", $iSize, "dword", $iAllocationType, "dword", $iProtect) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc Func __Extend_GetModuleHandle($vModule) Local $aCall = DllCall("kernel32.dll", "ptr", "GetModuleHandleW", "wstr", $vModule) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc Func __Extend_GetProcAddress($hHandle, $sFunc) Local $aCall = DllCall("kernel32.dll", "ptr", "GetProcAddress", "handle", $hHandle, "str", $sFunc) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc ...and then (modified Chimp's): #include <ie.au3> #include "ExtendObj.au3" $oMyObject = ObjectExtend(_IECreate()) ; just to have a "guinea pig" to experiment with Global $aDesiredProperties[] = ['Left=10', 'Top=10', 'Width=260', 'Height=350', 'AddressBar=0', 'MenuBar=0', 'StatusBar=0', 'ToolBar=0'] For $i = 0 To UBound($aDesiredProperties) - 1 $aSet = StringSplit($aDesiredProperties[$i], "=", 2) ; 2 -> $STR_NOCOUNT) $oMyObject.__propset__($aSet[0], $aSet[1]) Next Local $sHTML = '0x3C21444F43545950452068746D6C3E3C68746D6C3E3C686561643E3C2F68656' & _ '1643E3C626F64793E3C696D67207372633D2268747470733A2F2F636F6F6C6D617465726' & _ '9616C2E636F6D2F77702D636F6E74656E742F75706C6F6164732F323031332F30322F737' & _ '472697065732E676966222077696474683D2232323022206865696768743D22323930223' & _ 'E3C2F626F64793E3C2F68746D6C3E' $oMyObject.document.Write(BinaryToString($sHTML)) $oMyObject.document.close() $oMyObject.document.execCommand("Refresh") MsgBox(0, "Info", "Press OK to exit") $oMyObject.quit oHenry, FrancescoDiMuro, Gianni and 2 others 5 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Gianni Posted May 3, 2020 Share Posted May 3, 2020 This really is a gem, I mean for what it does, as for how it does it, unfortunately for me, I can't understand even one percent of that stuff, but I'm fascinated by it anyway, after all, only a wizard like @trancexx, or rather, only the queen of developers can produce these special effects Thank you so much for this other pearl of yours FrancescoDiMuro and trancexx 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
trancexx Posted May 4, 2020 Share Posted May 4, 2020 On 5/3/2020 at 8:32 AM, Chimp said: This really is a gem, I mean for what it does, as for how it does it, unfortunately for me, I can't understand even one percent of that stuff, but I'm fascinated by it anyway, after all, only a wizard like @trancexx, or rather, only the queen of developers can produce these special effects Thank you so much for this other pearl of yours Actually it's pretty straightforward. An object is created that has a pointer to the original object as its property, and all the calls to methods of this new object are simply translated to the original one. Obviously GetIDsOfNames and Invoke of the new object checks for call to the new methods and alters the parameters array accordingly before calling the original. The only thing that was truly a challenge was how to free dynamically allocated memory from within itself. Doing it from x64 code is easy due to specific calling convention and execution algorithm, but from x86 it's nightmare until you figure out that it is not the spoon that bends, lol. There is no spoon. The code is super interesting, I wish I had a chance to see something like that ten years ago, and be able to learn from it. I would have asked thousands of questions. Who knows... maybe I'd be ruling the world now, and not that fuc*ker. This way I had to do it all by myself with little chance of ruling. The. World. Gianni 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
RTFC Posted May 5, 2020 Share Posted May 5, 2020 @trancexx: You rule anyway! Gianni and trancexx 1 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O 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