Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Passing 2D byte array from C# to CLR dll

$
0
0

Hello,

My CLR class has to get array of C# strings and convert them to 1D array of char pointers passed to a Win32 DLL.

In C# I ran:

private byte[][] convertToBytes(String[] strings)
        {
                byte[][] data = new byte[strings.Length][];
                for (int i = 0; i < strings.Length; i++)
                {
                    String s = strings[i];
                    data[i] = Encoding.ASCII.GetBytes(s);
                }
                return data;
        }

String[] strings = new String[]{"first", "second"};

byte[][] byteStrings = convertToBytes(strings);

MySafeClass.OpenFile(byteStrings);

What should be the prototype in the CLR code ?

I tried:

int OpenFile (array <System::Byte^>^ byteArray)
{
// Do something
}

But according to the C# compiler:

Argument 1: cannot convert from 'byte[][]' to 'System.ValueType[]'

Can you help ?

Best regards,

Z.V


Viewing all articles
Browse latest Browse all 1710

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>