到目前为止,我已经了解了如何使用Typelib在Euphoria之间传递Unicode字符串、bSTR。到目前为止,我不能理解的是如何创建和传回BSTR数组。
到目前为止,我拥有的代码(以及用于EuCOM本身的include
和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
类型库的一部分是:
[
helpstring("get an array of strings"),
entry("REALARR")
]
void __stdcall REALARR( [out,retval] VARIANT* res );
VB6中的测试代码是:
...
Dim v() as String
V = REALARR()
...
到目前为止,我所得到的只是一个来自DLL的错误'0‘。有什么想法吗?有没有人?
发布于 2009-11-05 02:43:50
您应该使用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 )
发布于 2008-10-17 07:15:11
我已经通过他们的forum与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
发布于 2008-10-20 15:42:04
好的,var
还没有初始化。这并不重要,因为例程仍然会崩溃。尽管如此,我们需要一个
var = allocate( 16 )
就在make_variant之前
https://stackoverflow.com/questions/199612
复制相似问题