arraysuwpmidlwrl

Retrieve array through WRL idl


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


Solution

  • 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.