2008-10-14 75 views
1

到目前为止,我已经想出了如何使用Typelib传递Unicode字符串bSTRs到和来自Euphoria DLL。到目前为止,我无法弄清楚如何创建并传回一组BSTR。如何使用EuCOM在Euphoria中创建BSTR的变体数组?

我有迄今(与include S表示EUCOM本身和零件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”。有任何想法吗?任何人?

回答

1

之前,您应该使用​​功能。它在Utilities下记录(隐藏?)。基本上,把你的BSTR指针变成一个序列,并将它传递到​​:

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) 
+0

谢谢,马特,我已经给它去了。 – bugmagnet 2009-11-05 02:28:34

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 
0

好的,var尚未初始化。这并不重要,因为例程仍然崩溃。尽管如此,人们需要一种

var = allocate(16) 

只是make_variant