Hi, I am having a real problem. I have made an ATL service which serves up some data in the form of structures. My application can request one or all structures to be read, it's pretty simple that way.

However, if I return an array of structs, only the first one is valid and all subsequent structs are completely garbage when they get back to the app, even though I can see them being built properly in the service.

Here is the relevant code:

Service:

MyService.idl

[id(1), helpstring("method get_AllLicenseData")] HRESULT get_AllLicenseData([out] ULONG* bytes, [out, size_is(, *bytes)] SM_LICENSE_DATA ** license_data, [out,retval] LONG * retVal);

The SM_LICENSE_DATA only contains static data members, no pointers or anything. It's pretty simple. I will post if needed.

Here is how I allocate the memory. num is set to the number of structs and is always greater than zero in this case. I know, I have tested it. It is in fact 3 for my tests. A valid memory handle is returned.

Code:
long LICENSE_MANAGER::get_AllLicenseData(SM_LICENSE_DATA **_ld, unsigned long *_bytes)
{

...

*_ld = static_cast< SM_LICENSE_DATA * >(CoTaskMemAlloc(sizeof(SM_LICENSE_DATA) * num));

...
I then populate the array and it seems to work. I can trace it all the way to the point it leaves the service and it is all good.

Now for the odd buit, it gets back to the app ad only the first structure is valid, all the rest have random data in them. Here is how I call it:

Code:
SM_LICENSE_DATA *ld;

HRESULT         hr;
ULONG           bytes;
LONG            result;

hr = pSM->get_AllLicenseData(&bytes, &ld, &result);
pSM is good, everything returns with successful codes.

Any ideas? I am sure I missed something simple but what?

Thanks!