0

I need to pass via Microsoft RPC structure with conformant array. This is how I write it in IDL:

struct BarStruct
{
  byte a;
  int b;
  byte c;
long lArraySize;
[size_is(lArraySize)] char achArray[*];
};

Generated header:

struct BarStruct
    {
    byte a;
    int b;
    byte c;
    long lArraySize;
    char achArray[ 1 ];
    } ;

Why achArray is fixed length of 1? How to pass array with for example 10 elements to it?

vico
  • 17,051
  • 45
  • 159
  • 315

1 Answers1

0

Something like this:

BarStruct* p = (BarStruct*)CoTaskMemAlloc(
    offsetof(BarStruct, achArray) + 10*sizeof(char));

Basically, you need to allocate memory as if the structure had achArray[10] member at the end. offsetof(BarStruct, achArray) gives you the size of the fixed part of the structure, up to but not including achArray. To this, you add variable size of the array.

Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85