【问题标题】:How do I create a variant array of BSTR in Euphoria using EuCOM?如何使用 EuCOM 在 Euphoria 中创建 BSTR 的变体数组?
【发布时间】:2008-10-14 00:47:02
【问题描述】:

到目前为止,我已经弄清楚了如何使用 Typelib 将 Unicode 字符串 bSTR 传入和传出 Euphoria DLL。到目前为止,我不知道如何创建和传回 BSTR 数组。

到目前为止我拥有的代码(以及用于 EuCOM 本身和部分 Win32lib 的 includes):

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”。有任何想法吗?有人吗?

【问题讨论】:

    标签: variant typelib safearray


    【解决方案1】:

    您应该使用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 )
    

    【讨论】:

    • 谢谢,Matt,我已经尝试过了。
    【解决方案2】:

    我已经通过他们的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 
    

    【讨论】:

      【解决方案3】:

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

      var = allocate( 16 )
      

      就在 make_variant 之前

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多