I'm mostly at the end of my rope. I have a cDicObj object that contains a custom udt. I can add it successfully and the first retrieval works. On the second retrieval of the same key, it fails. Nothing happened between the two retrievals.
The object oPageCanvasList is in my class private space as a cDicObj.
Adding code
Private SUB cPDF.CreateCanvas(BYREF uCanvas As PageCanvas)
DIM dv AS DVARIANT
DIM sCanvasID AS DWSTRING
sCanvasID = "C" + FORMAT(oPageCanvasList.Count + 1)
dv.PutBuffer(@uCanvas, SIZEOF(uCanvas))
oPageCanvasList.Add(sCanvasID,dv)
oPageStreamList.Add("")
End Sub
The retrieval code (with some prints so I could see what is going on) is:
Private SUB cPDF.GetCanvas(BYVAL nIndex AS LONG, BYREF uCanvas AS PageCanvas)
DIM dv AS DVARIANT
DIM sCanvasID AS DWSTRING
sCanvasID = "C" + FORMAT(nIndex)
dv = oPageCanvasList.Item(sCanvasID)
print "GetCanvas, ID=" + sCanvasID
dv.ToBuffer(@uCanvas, SIZEOF(uCanvas))
print "Get Canvas Error Info=" + dv.GetErrorInfo(-1)
sleep
End Sub
Running console results:
GetCanvas, ID=C1
Get Canvas Error Info=The operation completed successfully.
Getting Canvas
Width=612
Height=792
LeftMargin=18
TopMargin=18
RightMargin=18
BottomMargin=18
DrawingHeight=756
DrawingWidth=576
Orientation=1
ObjectNumber=0
StreamObject=0
StreamComplete=false
GetCanvas, ID=C1
Get Canvas Error Info=The operation completed successfully.
GetCanvas, ID=C1
Get Canvas Error Info=Error &h80070057
The parameter is incorrect.
What is going on here?
I don't see anything wrong in the posted code, bt I can't test it.
I have made a quick test and it works no matter how many times I call GetUdt.
TYPE Foo
x AS long
y as long
b as WSTRING * 260
END type
' // Creates an instance of the CDicObj class
DIM SHARED pDic AS CDicObj
SUB GetUdt(BYREF tFoo2 AS Foo)
DIM dws AS DWSTRING = "Foo2"
'DIM dws AS DWSTRING = "Foo" + WSTR(2)
'DIM dws AS DWSTRING = "Foo" + FORMAT(2)
DIM dvFoo2 AS DVARIANT
'dvFoo2 = pDic.Item("Foo2")
dvFoo2 = pDic.Item(dws)
dvFoo2.ToBuffer(@tFoo2, SIZEOF(tFoo2))
print dvFoo2.GetErrorInfo(-1)
END SUB
'' // Creates an instance of the Foo type
'DIM t AS Foo = (12345, 72727, "Test string")
'' // Assigns it to a DVARIANT
'DIM dv AS DVARIANT
'dv.PutBuffer(@t, SIZEOF(t))
'' // Adds the type to the dictionary
'pDic.Add "Foo1", dv
' // Creates another instance of the Foo type
DIM t2 AS Foo = (111111, 22222, "Test string 2")
' // Assigns it to a DVARIANT
DIM dv2 AS DVARIANT
dv2.PutBuffer(@t2, SIZEOF(t2))
' // Adds the type to the dictionary
pDic.Add "Foo2", dv2
'' // Gets Foo1 from the dictionary
'DIM dvFoo1 AS DVARIANT
'dvFoo1 = pDic.Item("Foo1")
'' // Assigns it to a DVARIANT
'DIM tFoo1 AS Foo
'dvFoo1.ToBuffer(@tFoo1, SIZEOF(tFoo1))
'print dvFoo1.GetErrorInfo(-1)
'' // DIsplay the values
'print tFoo1.x
'print tFoo1.y
'print tFoo1.b
'' // Gets Foo2 from the dictionary
'DIM dvFoo2 AS DVARIANT
'dvFoo2 = pDic.Item("Foo2")
'' // Assigns it to a DVARIANT
'DIM tFoo2 AS Foo
'dvFoo2.ToBuffer(@tFoo2, SIZEOF(tFoo2))
'print dvFoo2.GetErrorInfo(-1)
'' // DIsplay the values
'print tFoo2.x
'print tFoo2.y
'print tFoo2.b
DIM tFoo2 AS Foo
GetUdt(tFoo2)
print tFoo2.x
print tFoo2.y
print tFoo2.b
tFoo2.x = 0
tFoo2.y = 0
tFoo2.b = ""
print "--------------"
GetUdt(tFoo2)
print tFoo2.x
print tFoo2.y
print tFoo2.b
tFoo2.x = 0
tFoo2.y = 0
tFoo2.b = ""
print "--------------"
GetUdt(tFoo2)
print tFoo2.x
print tFoo2.y
print tFoo2.b
print "--------------"