c++ - Return SAFEARRAY of custom interface types to VB6 through COM -


is possible return array of defined interface objects c++ com function (vc6) vb6 client? i've scoured web , haven't been able come across describes need do. i've seen lot of passing bstr , variant types, need way have client side utilise interface type return inside array.

what assume i'll need do
- use safearray
- use safearray vt_unknown type, in turns means need place objects array iunknown objects.

from here on in i'm stumped. possible interpret iunknown type in vb6, , somehow turn type require? or going in complete wrong way...

clarification:
interfaces being placed in collection being used mimic struct. need pass array of structs.

i've come solution suitable purposes, despite not being set out in question.

my solution create com function takes safearray parameter , modifies it, instead of returning created array. vb6 client instantiates array, , passes c++ populating. envision future usage include precursor function vb6 calls determine required size of array. reference, here's code snippets:

interface function:

[id(4), helpstring("method populatewithstruct")] hresult populatewithstruct([in,out]safearray (ireturnstruct*)*pparray, [out,retval] long*plresult); 

where ireturnstruct interface containing property values, acting struct:

interface ireturnstruct : idispatch {     [propget, id(1), helpstring("property num1")] hresult num1([out, retval] long *pval);     [propget, id(2), helpstring("property str1")] hresult str1([out, retval] bstr *pval); }; 

and implemented returnstruct

[     uuid(843870d0-e3b3-4123-82b4-74de514c33c9),     helpstring("returnstruct class") ] coclass returnstruct {     [default] interface ireturnstruct; }; 

populatewithstruct has following definition:

stdmethodimp cctestinterface::populatewithstruct(safearray **pparray, long *plresult) {     long llowerbound = -1;     long lupperbound = -1;     safearraygetlbound(*pparray, 1, &llowerbound);     safearraygetubound(*pparray, 1, &lupperbound);      long larraysize = lupperbound - llowerbound;      vartype type;     safearraygetvartype(*pparray, &type);      if (larraysize > 0)     {         ( int = llowerbound; < lupperbound; ++i)         {             ccomptr<creturnstruct> pretstruct;             hresult hr = cocreateinstance(__uuidof(returnstruct), null, clsctx_all, __uuidof(iunknown), reinterpret_cast<void **>(&pretstruct));             if (succeeded(hr))             {                 pretstruct->initialise();                 hr = safearrayputelement(*pparray, (long*)&i, pretstruct);                 if (failed(hr))                 {                     return hr;                 }                 pretstruct.release();             }         }         safearrayunaccessdata(*pparray);     }      *plresult = 1;      return s_ok; } 

on vb side:

dim obj atl_servicetestlib.ctestinterface set obj = new ctestinterface  dim result long dim retstructs(3) returnstruct  result = obj.populatewithstruct(retstructs()) 

any comments on approach?


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -