Dear All,
using MATLAB 2009b, I created the DLL (first_lib.dll, first_lib.h and first_lib.lib) from MATLAB function (first.m) using mcc and I would like to call it in a C code using Microsoft Visual C++ 2008 (Express Edition) which I downloaded from internet as free s/w.
I am posting the complete code here with compilation errors while compiling the C code (Please advice on that):
Reported Errors & warnings are:
1) error C2275: 'mxArray' : illegal use of this type as an expression
c:\program files\matlab\r2009a\extern\include\matrix.h(292) : see declaration of 'mxArray'
2) warning C4047: '=' : 'int' differs in levels of indirection from 'void *'
3) warning C4047: '=' : 'int' differs in levels of indirection from 'mxArray *'
4) warning C4047: 'function' : 'const mxArray *' differs in levels of indirection from 'int'
5) warning C4024: 'mxGetPr_proxy' : different types for formal and actual parameter 1
6) error C2172: 'memcpy' : actual parameter is not a pointer : parameter 2
Please advice on how to compile it and run it.
I am posting my complete C code here, where mlfFirst is the function call.
Code:
#ifdef _MSC_VER // if MS Visual C++
#pragma warning(push)
#pragma warning(disable:4996)
#pragma comment(lib, "libdfblas.lib")
#pragma comment(lib, "libdflapack.lib")
#pragma comment(lib, "libemlrt.lib")
#pragma comment(lib, "libeng.lib")
#pragma comment(lib, "libfixedpoint.lib")
#pragma comment(lib, "libmex.lib")
#pragma comment(lib, "libmwblas.lib")
#pragma comment(lib, "libmwlapack.lib")
#pragma comment(lib, "libmwmathutil.lib")
#pragma comment(lib, "libmwservices.lib")
#pragma comment(lib, "libmx.lib")
#pragma comment(lib, "libut.lib")
#pragma comment(lib, "mclcom.lib")
#pragma comment(lib, "mclcommain.lib")
#pragma comment(lib, "mclmcr.lib")
#pragma comment(lib, "mclmcrrt.lib")
#pragma comment(lib, "mclxlmain.lib")
#pragma comment(lib, "first_lib.lib")
#endif
#include
#include ;
#include "mex.h"
#include "first_lib.h"
int main()
{
double a,b,c, Ans;
a = 1; b =2; c=3;
mxArray *pmX, *pmY, *pmZ;
mxArray* pmAns = NULL;
mclinitializeApplication(NULL,0);
*mxGetPr(pmX) = a;
*mxGetPr(pmY) = b;
*mxGetPr(pmZ) = c;
first_libInitialize();
memcpy(mxGetPr(pmX),&a, sizeof(double)*1);
memcpy(mxGetPr(pmY),&b, sizeof(double)*1);
memcpy(mxGetPr(pmZ),&c, sizeof(double)*1);
mlfFirst(1,&pmAns,pmX,pmY,pmZ);
Ans = *mxGetPr(pmAns);
first_libTerminate();
printf("%f %f\n", Ans);
mxDestroyArray(pmX);
mxDestroyArray(pmY);
mxDestroyArray(pmZ);
mxDestroyArray(pmAns);
mclTerminateApplication();
printf("Hello World");
return 0;
}