Marshal static array inside the structure from C++ to C#

A

Ananas

Hi,

Please give me an idea how to send a static array from dll written on
C++ to C# application.

This is a C++ code:
const SIGNATURE_LENGTH = 50;

struct Info
{
unsigned int Signature[SIGNATURE_LENGTH];
}


This is a C# code:
[StructLayout( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
public struct Info
{
[MarshalAs(UnmanagedType.ByValArray,SizeConst=50)]
uint[] Signature;
}

The problem is that I have to specify the length of the static array to
be marshalled from dll. But if the length changes in future then I have
to rebuild my c# code according with new static array length?

How to make universal C# code for to marshal static array inside the
structure?

Thanks in advise,
Eugene.
 
M

Mattias Sjögren

How to make universal C# code for to marshal static array inside the
structure?

Skip the structure and use a dynamically allocated buffer to hold the
data instead.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top