EuCOMを使用してEuphoriaでBSTRのバリアント配列を作成するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/199612

  •  11-07-2019
  •  | 
  •  

質問

これまで、Typelibを使用して、Euphoria DLLとUnicode文字列、bSTRをやり取りする方法を見つけました。これまでのところ私が理解できないのは、BSTRの配列を作成して返す方法です。

これまでのコード(EuCOM自体とWin32libの一部の include sとともに):

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()
...

これまでのところ、DLLからエラー「0」を取得できました。何か案は?誰ですか?

役に立ちましたか?

解決

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 )

他のヒント

私は、フォーラム、そしてここまで進んでいます。 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 

さて、 var は初期化されていません。ルーチンがまだクラッシュするので、それは重要ではありません。それでも、必要なのは

var = allocate( 16 )

make_variantの直前

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top