首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用EuCOM在Euphoria中创建BSTR的变体数组?

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

Stack Overflow用户
提问于 2008-10-14 00:47:02
回答 3查看 1.3K关注 0票数 1

到目前为止,我已经了解了如何使用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‘。有什么想法吗?有没有人?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 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 )
票数 1
EN

Stack Overflow用户

发布于 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 
票数 0
EN

Stack Overflow用户

发布于 2008-10-20 15:42:04

好的,var还没有初始化。这并不重要,因为例程仍然会崩溃。尽管如此,我们需要一个

var = allocate( 16 )

就在make_variant之前

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/199612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档