0

I am fairly new to C++/CX programming, please correct the question for any mistakes.

I am trying to create a Public API in Windows Runtime using C++/CX, where I have to define a method which has two dimensional byte array as out parameter. I think, I cannot use Array<byte>^ for this purpose as it is suppose to be a one dimensional array. But Visual Studio complier suggests me to have declaration like below

void getByteArrays(int *size, Array<byte>^* arr);

  1. But I cannot initialize arr in the implementation, I think the reason is same, Array can be only one dimensional array?

But I can still send Array<byte>^ though using below initialization.

byte *buffer = /* Something */ ;
arr[0] = ref new Array<byte>(buffer, size);
  1. Is this approach correct?
  2. If not, what is the best way to have a two dimensional byte array as out parameter using Platform namespace only?

Below is my complete code

void getByteArrays(int *size, Array<byte>^* arr)
{
    byte *buffer = /* Something */;
    (*size) = /* Something */;

    arr = ref new Array<byte>(2); //How do i tell compiler that it has 2 rows?
    arr[0] = ref new Array<byte>(buffer, (*size));
    arr[1] = ref new Array<byte>(buffer, (*size));
}

Update : I think, complier was suggesting to pass the Array<byte>^ pointer as reference for out parameter. So, it is still be a one-dimensional array.

Trident
  • 810
  • 9
  • 20
  • 1
    Do check [the docs](https://learn.microsoft.com/en-us/cpp/cppcx/array-and-writeonlyarray-c-cx), it explicitly mentions that this is not supported (Jagged Array section). You have to expose it as a vector-of-vectors, `IVector^>` – Hans Passant May 02 '17 at 13:05
  • It appears to be the case, as the complier was trying to tell me to pass the reference of `Array^`. Can you provide an example or reference, if you have any? – Trident May 02 '17 at 13:11
  • If you want use the two dimensional Array, please refer [this similar question](http://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new). – Jayden May 03 '17 at 05:40

0 Answers0