code_junkie

How do I create a variant array of BSTR in Euphoria using EuCOM?

Nov 11th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. global function REALARR()
  2. sequence seq
  3. atom psa
  4. atom var
  5. seq = { "cat","cow","wolverine" }
  6. psa = create_safearray( seq, VT_BSTR )
  7. make_variant( var, VT_ARRAY + VT_BSTR, psa )
  8. return var
  9. end function
  10.  
  11. [
  12. helpstring("get an array of strings"),
  13. entry("REALARR")
  14. ]
  15. void __stdcall REALARR( [out,retval] VARIANT* res );
  16.  
  17. ...
  18. Dim v() as String
  19. V = REALARR()
  20. ...
  21.  
  22. sequence s, bstrs
  23. s = {"A", "B"}
  24. bstrs = {}
  25. for i = 1 to length(s) do
  26. bstrs &= alloc_bstr( s[i] )
  27. end for
  28.  
  29. atom array
  30. array = create_safearray( bstrs, VT_BSTR )
  31.  
  32. ...
  33.  
  34. destroy_safearray( array )
  35.  
  36. global function REALARR()
  37. atom psa
  38. atom var
  39. atom bounds_ptr
  40. atom dim
  41. atom bstr
  42. object void
  43.  
  44. dim = 1
  45. bounds_ptr = allocate( 8 * dim ) -- now figure out which part is Extent and which is LBound
  46. poke4( bounds_ptr, { 3, 0 } ) -- assuming Extent and LBound in that order
  47.  
  48. psa = c_func( SafeArrayCreate, { VT_BSTR, 1, bounds_ptr } )
  49.  
  50. bstr = alloc_bstr( "cat" )
  51. poke4( bounds_ptr, 0 )
  52. void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr})
  53. free_bstr( bstr )
  54.  
  55. bstr = alloc_bstr( "cow" )
  56. poke4( bounds_ptr, 1 )
  57. void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr})
  58. free_bstr( bstr )
  59.  
  60. bstr = alloc_bstr( "wolverine" )
  61. poke4( bounds_ptr, 2 )
  62. void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr})
  63. free_bstr( bstr )
  64.  
  65. make_variant( var, VT_ARRAY + VT_BSTR, psa )
  66. return var
  67. end function
  68.  
  69. var = allocate( 16 )
Add Comment
Please, Sign In to add comment