¿Cómo creo una matriz variante de BSTR en Euphoria usando EuCOM?
Pregunta
Hasta ahora he descubierto cómo pasar cadenas Unicode, bSTRs, desde y hacia una DLL Euphoria usando un Typelib. Lo que no puedo entender, hasta ahora, es cómo crear y devolver una matriz de BSTR.
El código que tengo hasta ahora (junto con include
s para EuCOM y partes de Win32lib):
global function REALARR()
sequence seq
atom psa
atom var
seq = { "cat","cow","wolverine" }
psa = create_safearray( seq, VT_BSTR )
make_variant( var, VT_ARRAY + VT_BSTR, psa )
return var
end function
Parte de typelib es:
[
helpstring("get an array of strings"),
entry("REALARR")
]
void __stdcall REALARR( [out,retval] VARIANT* res );
Y el código de prueba, en VB6 es:
...
Dim v() as String
V = REALARR()
...
Hasta ahora, todo lo que he conseguido es un error '0' de la DLL. ¿Algunas ideas? ¿Alguien?
Solución
Debería usar la función create_safearray ()
. Está documentado (¿oculto?) En Utilidades. Básicamente, coloque sus punteros BSTR en una secuencia y páselos a create_safearray ()
:
sequence s, bstrs
s = {"A", "B"}
bstrs = {}
for i = 1 to length(s) do
bstrs &= alloc_bstr( s[i] )
end for
atom array
array = create_safearray( bstrs, VT_BSTR )
...
destroy_safearray( array )
Otros consejos
He estado en contacto con la gente de Euphoria a través de su foro , y he llegado hasta aquí. La rutina falla en la línea make_variant. No lo he descubierto más allá de eso y tampoco lo han hecho.
global function REALARR()
atom psa
atom var
atom bounds_ptr
atom dim
atom bstr
object void
dim = 1
bounds_ptr = allocate( 8 * dim ) -- now figure out which part is Extent and which is LBound
poke4( bounds_ptr, { 3, 0 } ) -- assuming Extent and LBound in that order
psa = c_func( SafeArrayCreate, { VT_BSTR, 1, bounds_ptr } )
bstr = alloc_bstr( "cat" )
poke4( bounds_ptr, 0 )
void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr})
free_bstr( bstr )
bstr = alloc_bstr( "cow" )
poke4( bounds_ptr, 1 )
void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr})
free_bstr( bstr )
bstr = alloc_bstr( "wolverine" )
poke4( bounds_ptr, 2 )
void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr})
free_bstr( bstr )
make_variant( var, VT_ARRAY + VT_BSTR, psa )
return var
end function
Bien, var
no se ha inicializado. No es que importe, ya que la rutina sigue fallando. Sin embargo, uno necesita un
var = allocate( 16 )
justo antes de make_variant