I have problems with the output parameter of the mshalling C ++ function returning an array of data in C #.
Here is the C ++ declaration:
#define DLL_API __declspec(dllexport)
typedef TPARAMETER_DATA
{
char *parameter;
int size;
} PARAMETER_DATA;
int DLL_API GetParameters(PARAMETER_DATA *outputData);
The function allocates memory for the char array, puts the data there and returns the number of allocated bytes in the "size" field. Here is my C # declaration:
[StructLayout(LayoutKind.Sequential)]
public struct PARAMETER_DATA
{
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.I1, SizeConst = 50000)]
public byte[] data;
[MarshalAs(UnmanagedType.I4)]
public int size;
}
[DllImport("thedll.dll", SetLastError = true, ExactSpelling = true)]
public extern static uint GetParameters(ref PARAMETER_DATA outputData);
When calling a function in C #, I get an empty structure (size = 0, an empty array). I tried passing the outputData parameter with initializing the data field to a new byte [50000], but the data is not being returned.
DLL ( ) , , .
# marshalling ( LPArray, LPString) - .
- ?
EDIT:
++ - .