2008-10-14 67 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

相關問題