كيف يمكنني إنشاء مجموعة البديل من BSTR في نشوة باستخدام القيادة الاوروبية الامريكية؟

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

  •  11-07-2019
  •  | 
  •  

سؤال

وحتى الآن لقد برزت كيفية تمرير سلاسل Unicode، bSTRs، من وإلى DLL نشوة باستخدام Typelib. ما لا أستطيع معرفة، حتى الآن، هو كيفية إنشاء وتمرير ظهر مجموعة من BSTRs.

ورمز لدي حتى الآن (جنبا إلى جنب مع includes عن القيادة الاوروبية الامريكية نفسها وأجزاء من 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

وجزء من typelib هو:

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

ورمز الاختبار، في VB6 هو:

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

وحتى الآن كل ما تمكنا من الحصول على هو خطأ '0' من DLL. أيه أفكار؟ أحد؟

هل كانت مفيدة؟

المحلول

ويجب عليك استخدام وظيفة 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 )

نصائح أخرى

ولقد كنت على اتصال مع الناس نشوة عبر بها <لأ href = "http://openeuphoria.org/EUforum/index.cgi؟module=forum&action=flat&id=102589#unread" يختلط = "نوفولو noreferrer" > منتدى ، ووصلت إلى هذا الحد. الروتين هو الفشل على خط 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 

حسنا، لم initialised var. لا يهم كما الروتين تزال تعطل. ومع ذلك، يحتاج المرء إلى

var = allocate( 16 )

وقبيل make_variant

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top