到目前为止,我已经学会了如何使用Typelib在Euphoria DLL之间传递Unicode字符串bSTR。到目前为止,我还不知道如何创建和传递一个BSTR数组。
到目前为止,我的代码(以及EuCOM本身和Win32lib部分的include
):
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
typelib的一部分是:
[
helpstring("get an array of strings"),
entry("REALARR")
]
void __stdcall REALARR( [out,retval] VARIANT* res );
VB6中的测试代码是:
...
Dim v() as String
V = REALARR()
...
到目前为止,我所得到的只是DLL中的一个错误"0"。有什么想法吗?任何人
您应该使用create_safearray()
函数。它记录在实用程序下(隐藏?)。基本上,将BSTR指针放入一个序列中,并将其传递给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 )
我已经通过他们的论坛与Euphoria的人们取得了联系,并且已经走到了这一步。例程在make_variant行失败。我还没有想清楚,他们也没有。
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
好的,var
尚未初始化。这并不重要,因为常规程序仍然崩溃。尽管如此,还是需要
var = allocate( 16 )
就在make_variant 之前