Im trying to Marshall a C struct into C# like so
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Shader
{
public uint id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Raylib.MAX_SHADER_LOCATIONS)]
public int[] locs;
}
And its C counterpart:
typedef struct Shader {
unsigned int id; // Shader program id
int locs[MAX_SHADER_LOCATIONS]; // Shader locations array
} Shader;
MAX_SHADER_LOCATIONS is a constant set to 32 in both C and C#.
This solution here is the same as this Marshaling C++ struct with fixed size array into C#.
The function I am using to test it is
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Shader LoadShader(string vsFileName, string fsFileName);
And its C counterpart:
Shader LoadShader(const char *vsFileName, const char *fsFileName)
When I try to use this function I get the error "Method's type signature is not PInvoke compatible". Any idea what I'm doing wrong?