I´m trying to use Pinvoke to call Matlab functions from C#.
My project configuration is:
- C++ Project that uses "mex.h" to call "mexCallMATLAB" interface
Example:
#include "stdafx.h"
#include <stdarg.h>
#include <string>
#include "matrix.h"
#include "mex.h"
extern "C" _declspec(dllexport) bool blockExists()
{
std::string blockPath = "model/myblockpath";
mxArray *pin[1];
int nin = 1;
mxArray *pout[1];
int nout = 1;
pin[0] = mxCreateString( blockPath.c_str() );
if ( mexCallMATLAB( nout, pout, nin, pin, "find_system" ) != 0 ) {
callStatus = false;
}
mxDestroyArray( pin[0] );
return callStatus;
}
- C# Project that uses PInvoke to call previous c++ project
Example:
using System.Runtime.InteropServices;
namespace ManagedMatlabWrapper
{
public class MatlabWrapper
{
[DllImport(@"MatlabAPI.dll")]
private static extern bool blockExists();
public static bool blockExistsAPI()
{
bool result = blockExists();
return result;
}
}
}
Everything compiles OK
But when I run the code, it gives me an error of DLL not found exception.
I checked the DLL generated using a dependency walker and it shows that some Matlab DLL are not found. If i change the code and remove any reference to Matlab, Pinvoke runs just fine.
Does anyone know whats missing? What should I do to call mexCallMATLAB from c#?