1

I have asked same question here as well.

I am having trouble with making API that would return Array of objects.
Here is what I have tried so far. I wrote method that would return array as parameter

HRESULT GetMyObjectList([out] UINT32* objCount, [out, size_is(*objCount)] MyObject myobj[*]);

This gives me following error: Error MIDL4048 [msg]Unsupported array pattern detected. [context]myobj

Also, I tried to add array into custom Object, i.e.

[version(1.0)]  
typedef struct MyCustomObject  
{  
    UINT32 count;  
    [size_is(count)] UINT32 someParams1[*]; 
} MyCustomObject;

In this case I am getting following error: Error MIDL4000 [msg]A structure field cannot be a type of pointer. [context]: someParams1 [ Field 'someParams1' of Struct 'MyName.Space.MyCustomObject' ]

Can anyone tell me what is the problem here? Or provide working example to retrive array of Objects through WRL idl

Cœur
  • 37,241
  • 25
  • 195
  • 267
miradham
  • 2,285
  • 16
  • 26

1 Answers1

2

The correct IDL for a buffer depends on whether it is in or out.

From windows.security.cryptography.idl in the SDK:

interface ICryptographicBufferStatics : IInspectable
{
  // other methods omitted...

  HRESULT CreateFromByteArray([in] UINT32 __valueSize, 
    [in] [size_is(__valueSize)] BYTE* value, 
    [out] [retval] Windows.Storage.Streams.IBuffer** buffer);

  HRESULT CopyToByteArray([in] Windows.Storage.Streams.IBuffer* buffer,
    [out] UINT32* __valueSize, 
    [out] [size_is(, *__valueSize)] BYTE** value);
}

Note that there is no "by ref" array type in WinRT - the array is always copied. Either the caller allocates it and the callee takes a copy, or the callee allocates it and the caller takes ownership.

Peter Torr - MSFT
  • 11,824
  • 3
  • 18
  • 51
  • do you happen to know how to have array inside struct which is inside namespace? When struct is outside of namespace it works just fine. But when I move it inside namespace Im getting `A structure filed cannot be a type of pointer` error – miradham Nov 09 '18 at 08:40
  • 1
    WinRT structs are value types and can only hold other value types. You need a runtime class if you want to have an array, but note as above it can't be modeled as a traditional property. – Peter Torr - MSFT Nov 11 '18 at 16:43