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

发布于 2024-07-07 08:56:37 字数 731 浏览 15 评论 0原文

到目前为止,我已经弄清楚如何使用 Typelib 在 Euphoria DLL 之间传递 Unicode 字符串、bSTR。 到目前为止,我不明白的是如何创建并传回 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

typelib的一部分是:

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

VB6中的测试代码是:

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

到目前为止我已经设法做到了get 是来自 DLL 的错误“0”。 有任何想法吗? 任何人?

So far I've figured out how to pass Unicode strings, bSTRs, to and from a Euphoria DLL using a Typelib. What I can't figure out, thus far, is how to create and pass back an array of BSTRs.

The code I have thus far (along with includes for EuCOM itself and parts of 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

Part of the typelib is:

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

And the test code, in VB6 is:

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

So far all I've managed to get is an error '0' from the DLL. Any ideas? Anyone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

年少掌心 2024-07-14 08:56:37

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

You should use the create_safearray() function. It's documented (hidden?) under Utilities. Basically, put your BSTR pointers into a sequence and pass it to 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 )
笑脸一如从前 2024-07-14 08:56:37

我通过他们的

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 

I've been in touch with the Euphoria people via their forum, and have gotten this far. The routine is failing on the the make_variant line. I haven't figured it out any further than that and neither have they.

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 
流星番茄 2024-07-14 08:56:37

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

var = allocate( 16 )

然而,在 make_variant 之前

Okay, var hasn't been initialised. Not that it matters as the routine still crashes. Nevertheless, one needs a

var = allocate( 16 )

just before the make_variant

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文