The correct marshalling for "mclIntializeApplication" is:
[DllImport((@"C:\Program Files\MATLAB\MATLAB Compiler Runtime\v80\runtime\win64\mclmcrrt8_0.dll, EntryPoint = "mclInitializeApplication_proxy", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)]
public static extern bool mclInitializeApplication([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] options, int count);
That is the first parameter is an array of strings (char**). You should then call it this way:
var options = new [] { "-nojvm" };
var result = mclInitializeApplication(options, options.Length);
To avoid passing length and controlling for boolean result you can also wrap above function to something more C# friendly:
public static void mclInitializeApplication(params string[] options)
{
var count = 0;
if (options != null) { count = options.Length; }
if (!_mclInitializeApplication(options, count))
{
var reason = mclGetLastErrorMessage();
throw new Exception(String.Format("Call to '{0}' failed: {1}", "mclInitializeApplication", reason));
}
}
With:
[DllImport(@"C:\Program Files\MATLAB\MATLAB Compiler Runtime\v80\runtime\win64\mclmcrrt8_0.dll", EntryPoint = "mclGetLastErrorMessage_proxy", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)]
private static extern IntPtr _mclGetLastErrorMessage();
public static String mclGetLastErrorMessage()
{
var ptr = _mclGetLastErrorMessage();
return Marshal.PtrToStringAnsi(ptr);
}
But, in my real opinion, if you want to target .NET, the best solution is to let Matlab to compile in .NET directly with the SDK provided by Mathworks.