What is the best way to get an array of bytes from C # to the C ++ component of WinRT

We have a WinRT component with business logic that internally massages the C ++ unsigned char buffer. Now we want to pass this buffer from C # byte[] . What would the ideal border look like, i.e. What would the signature of SomeWinRTFunction function SomeWinRTFunction below?

 void SomeWinRTFunction(something containing bytes from managed land) { IVector<unsigned char> something using the bytes given from managed land; } 

This kind of problem seems too new for search engines to find it ...

+6
source share
2 answers

In the C ++ part, the method should accept an uint8 platform array (equivalent to the C # byte).

 public ref class Class1 sealed { public: Class1(); //readonly array void TestArray(const Platform::Array<uint8>^ intArray) { } //writeonly array void TestOutArray(Platform::WriteOnlyArray<uint8>^ intOutArray) { } }; 

In the C # part, pass an array of bytes:

  protected override void OnNavigatedTo(NavigationEventArgs e) { Byte[] b = new Byte[2]; b[0] = 1; var c = new Class1(); c.TestArray(b); c.TestOutArray(b); } 
+7
source

In WinRT, IVector is projected as an IList, I'm not sure about the byte -> unsigned char, but I suspect that too.

FROM#

 byte[] array; SomeWinRTFunction(array); 

C ++

 void SomeWinRTFunction(IVector<unsigned char> bytes) { IVector<unsigned char> something using the bytes given from managed land; } 

This white paper may shed some light.

+2
source

Source: https://habr.com/ru/post/917625/


All Articles