Pass String to C Plugin

C#
[DllImport (“__Internal”)]
public static extern int createMP4([MarshalAs( UnmanagedType.LPStr )]string _filePath, int _imageCount);

C
int createMP4(char* _filePath, int _imageCount){
FILE f;
char
fname = sprintf(_filePath, _filePath, 0);
if ((f = fopen(fname, “r”)))
{
fclose(f);
return 1;
}
return 0;
}

The problem is _filePath is always NULL and I have no idea what I am doing… well at least not in the C area.

In the end I want to use apples AVFoundation to create an MP4. Not even sure if this will work from C. But I first tried objectiveC and then felt like killing something. For the sake of everything living I switched to C. At least something is happening now.

What is this line supposed to do?
Your code looks good. Check that string is not null on C# side first. Also, how do you check that string is not NULL on C side? Note, that you have to run XCode in Debug mode to properly show locals.

1 Like

That does look wrong, but does not change the _filePath value. Well,… should not really. Thanks for pointing that out :slight_smile:
My experiments have now taken me down the (apple) Swift rabbit hole and I am not enjoying it.