如何使用EuCOM在Euphoria中创建BSTR的变体数组?

时间:2008-10-14 00:47:02

标签: variant typelib safearray

到目前为止,我已经想出了如何使用Typelib将Unicode字符串bSTR传递给Euphoria DLL。到目前为止,我无法弄清楚如何创建和传回一系列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

类型库的一部分是:

  [
     helpstring("get an array of strings"), 
     entry("REALARR")
  ] 
  void __stdcall REALARR( [out,retval] VARIANT* res );

测试代码,在VB6中是:

...
Dim v() as String
V = REALARR()
...

到目前为止,我设法得到的是来自DLL的错误'0'。有任何想法吗?任何人吗?

3 个答案:

答案 0 :(得分:1)

您应该使用create_safearray()功能。它在Utilities下记录(隐藏?)。基本上,将您的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 )

答案 1 :(得分:0)

我通过forum与幸福感人物保持联系,并且已经走到了尽头。例程在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 

答案 2 :(得分:0)

好的,var尚未初始化。并不重要,因为例程仍然崩溃。然而,人们需要一个

var = allocate( 16 )

就在make_variant

之前