Problems passing arrays using COM

Hi everybody,
I have a COM interfcae, which use automation, having the next method:

[id(1), helpstring("method Register")HRESULT Register([in]int iLength, [in, size_is(iLength)] BSTR bstrarrPrms[]);

The problem is, that when from the client I try to pass the BSTR array, I can see in debug that only the first value of the received array (in the server) match the sent array values. The rest is
something haotic ("???"," ", etc).
I can use only the SAFEARRAY to pass arrays? In this mode doesn't work?
(I got the idea to use this way from the MIDL compiler reference, its more simpliest then using SAFEARRAYs).
Thanx, Tibi
tmolnarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

romanmCommented:
I would pass a structure in the form of

typedef struct _Data{
      long            Num;
      [size_is(NumNum)]BSTR* pList;
} Data,*pData;

to the function:

func([in] pData DataPtr);

you just have to create the struct in the sender.

0
naveenkohliCommented:
Can you post the client side code that is passing the array?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
romanmCommented:
well :

//lets say we have

const some_number = 100;

BSTR *dat;
dat = new BSTR[ some_number ];

//now:
Data dat_struct;
dat_struct.Num = some_number;
dat_struct.pList = dat;

func( &dat_struct );

//that's it

// cleanup:
delete[] dat;
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

tmolnarAuthor Commented:
I tried in two ways: dynamic allocation using "calloc" or static mode using an
array declaration (to see how its work).

typedef struct {
    char *name;
    char *val;
} entry;

...............
...............


BSTR* pbstrarrPrms = (BSTR*)calloc(NR_ENTRIES, sizeof(BSTR));
BSTR  bstrarrPrms [NR_ENTRIES];

for(int i=0; i<NR_ENTRIES+2;i++)
{
    pbstrarrPrms[i] = entries[i].val;
    bstrarrPrms[i]  = entries[i].val;
}
hr = pIRegister->Register(NR_ENTRIES,   bstrarrPrms);
hr = pIRegister->Register(NR_ENTRIES,   pstrarrPrms);


  In both cases I have the same result. The first value is OK, the nexts are not.
  If I replace 'entries[i].val' with a normal string like "everything"-->
....
    pbstrarrPrms[i] = "trying";
    bstrarrPrms[i]  = "to pass";
....
--> the result is the same.

0
tmolnarAuthor Commented:
romanm!!
I tried what yoy told me, but I got
HRESULT error code
 hr = Error: missing opetator, and the code is not reached at the server side.
(I used your code..)
0
tmolnarAuthor Commented:
Using the SAFEARRAY structure incorporated in a VARIANT structure I can send arrays. Why don't work using normal MIDL features?
0
tmolnarAuthor Commented:
Using the SAFEARRAY structure incorporated in a VARIANT structure I can send arrays. Why don't work using normal MIDL features?
(Becouse I have dual interface, and I have marshaller only to VARIANT tags, offered from oleaut32.dll ???)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.