I'm working with the game Arma 3 where you can write your own Extensions (means a C++ or C# library). These Extensions have a defined entry point which is this DLL interface
void __stdcall RVExtension(char *output, int outputSize, const char *function);
int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **args, int argCnt);
When implementing this into C# the entry point for RVExtension would be
[DllExport("_RVExtension@12", CallingConvention = CallingConvention.Winapi)]
public static void RvExtension(StringBuilder output, int outputSize,
[MarshalAs(UnmanagedType.LPStr)] string function)
{
output.Append("Foo");
}
I'm using this library for the DLLExport.
As the entry point for RVExtensionArgs is quite new I wanted to implement it aswell. My solution so far is this one here:
[DllExport("_RVExtensionArgs@20", CallingConvention = CallingConvention.Winapi)]
public static int RvExtensionArgs(StringBuilder output, int outputSize,
[MarshalAs(UnmanagedType.LPStr)] string function, [MarshalAs(UnmanagedType.LPArray)] string[] args,
int argCount)
{
output.Append("Foo");
}
In general this works however the array passed for the args argument is not converted properly. You only get the first element of the passed array.
I tried to define the LPArray SizeConst property but this has to be a fixed size I can't provide. The passed array elements can be up to 1024. Plus I got an MarshalException when accessing the DLL with my test console.
How can I fix this behaviour?