jugador Posted October 27, 2021 Share Posted October 27, 2021 Vbscript Set oDict = CreateObject("Scripting.FileSystemObject") Set oGetobj = GetObject("", "Scripting.FileSystemObject") WScript.Echo TypeName(oDict) WScript.Echo TypeName(oGetobj) Autoit Local $oDict = ObjCreate("Scripting.FileSystemObject") If IsObj($oDict) Then Local $oGetobj = ObjGet("", "Scripting.FileSystemObject") If @error Then MsgBox(0, "", "ObjGet failed.... Error code: " & Hex(@error, 8)) $oDict = 0 Exit Endif $oGetobj = 0 $oDict = 0 MsgBox(0, "", "ObjGet Test Ok") Endif Link to comment Share on other sites More sharing options...
JockoDundee Posted October 27, 2021 Share Posted October 27, 2021 Can we get that error code? Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Werty Posted October 27, 2021 Share Posted October 27, 2021 "ObjGet Failed.... Error code: 80020006" Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Musashi Posted October 27, 2021 Share Posted October 27, 2021 (edited) A COM Error Handler may provide additional info : expandcollapse popup; COM Error Handler : Local $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc"), $EventError Local $oDict, $oGetObj $oDict = ObjCreate("Scripting.FileSystemObject") ConsoleWrite("ObjCreate $oDict = " & @error & @CRLF) If IsObj($oDict) Then $oGetObj = ObjGet("", "Scripting.FileSystemObject") If @error Then MsgBox(0, "", "ObjGet failed.... Error code: " & Hex(@error, 8)) $oDict = 0 Exit EndIf $oGetObj = 0 $oDict = 0 MsgBox(0, "", "ObjGet Test Ok") EndIf Func MyErrFunc() ConsoleWrite(@LF & "===========================================================" & @LF & _ "! AutoItCOM Test -- We intercepted a !" & @LF & @TAB & _ "err.description : " & $oMyError.description & @LF & @TAB & _ "err.windescription : " & $oMyError.windescription & @TAB & _ "err.number : " & Hex($oMyError.number, 8) & @LF & @TAB & _ "err.lastdllerror : " & $oMyError.lastdllerror & @LF & @TAB & _ "err.scriptline : " & $oMyError.scriptline & @LF & @TAB & _ "err.source : " & $oMyError.source & @LF & @TAB & _ "err.helpfile : " & $oMyError.helpfile & @LF & @TAB & _ "err.helpcontext : " & $oMyError.helpcontext & @LF & _ "===========================================================" & @LF) Local $Err = $oMyError.number If $Err = 0 Then $Err = -1 $EventError = $Err ; to check for after this function returns EndFunc ;==>MyErrFunc Edited October 28, 2021 by Musashi typo "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
LarsJ Posted October 28, 2021 Share Posted October 28, 2021 Probably because the VBScript function GetObject() and the AutoIt function ObjGet() don't work in exactly the same way. Note that this VBScript code also works: Set oGetobj = GetObject("", "Scripting.FileSystemObject") WScript.Echo TypeName(oGetobj) GetObject() can thus create a new object if the parameters don't refer to an existing object. The way you execute GetObject() in your VBScript code, the function creates a new object because the parameters don't match an existing object. In your code, the two objects are different objects but of the same type. The AutoIt ObjGet() function doesn't create new objects. It only creates a reference to an existing object through a file name or a line in the Running Object Table (ROT). These two options are both demonstrated in the examples in the help file. ObjCreate("Scripting.FileSystemObject") in AutoIt doesn't create an object that can be referenced either through a file name or through the ROT. Therefore, ObjGet() fails. CreateObject("Scripting.FileSystemObject") in VBScript also doesn't create an object that can be referenced either through a file name or through the ROT. But GetObject() doesn't fail because in this situation it creates a new object. junkew and jugador 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
jugador Posted October 29, 2021 Author Share Posted October 29, 2021 (edited) @LarsJ @Danyfirex @Nine Try to get running Scripting.Dictionary object using ObjGet but failed (like describe in 1st post). So try with ObjCreateInterface instead of ObjGet to capture running Scripting.Dictionary and it worked. 1) but getting error at the end !> AutoIt3.exe ended.rc:-1073741819 2) Is there any wrong in using ObjCreateInterface instead of ObjGet to capture running object? expandcollapse popup#include <WinAPICom.au3> __Example1() Func __Example1() Local $String_A = "Apple" _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) Local $oDict_A = ObjCreate( "Scripting.Dictionary" ) If IsObj($oDict_A) Then $oDict_A.add("$String_A", $String_A) ConsoleWrite("----->" & @CRLF) ConsoleWrite("[$oDict_A] [$String_A] => " & $oDict_A.Item("$String_A") & @CRLF) Local $pObject = Ptr( $oDict_A ) Local $oDict_B = ObjCreateInterface($pObject, "{42C642C1-97E1-11CF-978F-00A02463E06F}", Default, False) If @error Then ConsoleWrite("ObjCreateInterface failed.... Error code: " & Hex(@error, 8) & @CRLF) $oDict_A = 0 Exit Endif Local $String_B = "Orange" $oDict_B.add("$String_B", $String_B) ConsoleWrite("----->" & @CRLF) ConsoleWrite("[$oDict_B] [$String_B] => " & $oDict_B.Item("$String_B") & @CRLF) ConsoleWrite("[$oDict_B] [$String_A] => " & $oDict_B.Item("$String_A") & @CRLF) ConsoleWrite("----->" & @CRLF) ConsoleWrite("[$oDict_A] [$String_B] => " & $oDict_A.Item("$String_B") & @CRLF) ConsoleWrite("----->" & @CRLF) _WinAPI_CoUninitialize() $oDict_B = 0 $oDict_A = 0 Endif EndFunc Edited October 29, 2021 by jugador Link to comment Share on other sites More sharing options...
LarsJ Posted October 29, 2021 Share Posted October 29, 2021 I assume that your expectation of the code line with the ObjCreateInterface() function is that it gives you a new reference to the $oDict_A object. Ie. that $oDict_A and $oDict_B are two different references to the same object. But that's not the case. $oDict_B is a new object apparently created in the same memory block as $oDict_A. That's why you get Memory Access Violation errors. You also assume that your code works. But it doesn't. This is because you have only tested the code that works. You haven't tested the code that doesn't work. You create two references $oDict_A and $oDict_B to the same object this way. Because they are two references to the same object, this code works. Example() Func Example() Local $oDict_A = ObjCreate( "Scripting.Dictionary" ) ; Object reference counter = 1 $oDict_A( "Test" ) = 123 ConsoleWrite( "$oDict_A( ""Test"" ) = " & $oDict_A( "Test" ) & @CRLF ) $oDict_B = $oDict_A ; $oDict_A and $oDict_B references the same object ; Object reference counter = 2 $oDict_A = 0 ; Object reference counter = 1 ConsoleWrite( "$oDict_B( ""Test"" ) = " & $oDict_B( "Test" ) & @CRLF ) EndFunc If you test the same code (deletion of $oDict_A) with your $oDict_A and $oDict_B objects you'll see that the code doesn't work after deletion of $oDict_A. expandcollapse popup#include <WinAPICom.au3> __Example1() Func __Example1() Local $String_A = "Apple" _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) Local $oDict_A = ObjCreate( "Scripting.Dictionary" ) If IsObj($oDict_A) Then $oDict_A.add("$String_A", $String_A) ConsoleWrite("----->" & @CRLF) ConsoleWrite("[$oDict_A] [$String_A] => " & $oDict_A.Item("$String_A") & @CRLF) Local $pObject = Ptr( $oDict_A ) Local $oDict_B = ObjCreateInterface($pObject, "{42C642C1-97E1-11CF-978F-00A02463E06F}", Default, False) If @error Then ConsoleWrite("ObjCreateInterface failed.... Error code: " & Hex(@error, 8) & @CRLF) $oDict_A = 0 Exit Endif $oDict_A = 0 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite("----->" & @CRLF) ConsoleWrite("$oDict_A has been deleted" & @CRLF) Local $String_B = "Orange" $oDict_B.add("$String_B", $String_B) ConsoleWrite("----->" & @CRLF) ConsoleWrite("[$oDict_B] [$String_B] => " & $oDict_B.Item("$String_B") & @CRLF) ConsoleWrite("[$oDict_B] [$String_A] => " & $oDict_B.Item("$String_A") & @CRLF) ConsoleWrite("----->" & @CRLF) _WinAPI_CoUninitialize() $oDict_B = 0 Endif EndFunc The fact that $oDict_B doesn't work when $oDict_A is deleted clearly indicates that $oDict_A and $oDict_B aren't references to the same object. If they were, the code would have worked. $oDict_A and $oDict_B are two different objects. That parts of the code works as in your example along with all the Memory Access Violation errors indicates that the two objects have overlapping memory blocks. If you just want to create a new reference to an existing object simply use $oDict_B = $oDict_A. Musashi and jugador 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
jugador Posted October 30, 2021 Author Share Posted October 30, 2021 Thanks @LarsJ Your style of explaining things with example code and detail note make it easy to understand . 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