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.
#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.