Asked by:
Using Matlab Dlls

Hi everybody !
I am a Matlab Programmer. I create some Dlls from my .m files.
For the first test, my .m file contains only one function with one argument. the entire .m file is as follows:
function y=test(x)
y=x^2;
Then, by using the following command , I created the Dll and some other files:
mcc B csharedlib:testlib test.m
These files listed below:
testlib.c testlib.dll testlib.exp testlib.exports testlib.h testlib.lib testlib.prj testlib_mcc_component_data.c
Now I want simply write a visaul c++ 2008 windows forms application that use this function.
There are many topics in forum about Dlls, but I could not use those helps because I very new in VC++.
If anyone can help me with detailed explanation I'll be very very grateful.
 Changed type Engineer Mahdi Monday, November 23, 2009 7:06 PM I have some questions
Question
All replies

Look at this article at CodeProject.
 Proposed as answer by Nikita Leontiev Friday, December 04, 2009 11:38 AM









Matlab.h is situated in <matlab dir>\extern\include. You should go Tools menu > Options > Projects and Solutions > VC++ Directories, select Show directories for: Include files and add dir to the list.Additional info in this article that I found on mathworks site.
 Proposed as answer by Nikita Leontiev Friday, December 04, 2009 11:38 AM

I did the instructions.
/* Call the implementation function */ y_ptr = mlfTestdll(x_ptr);
What's the number of arguments of above function?
My cpp file looks:
#include "testdlllib.h" //#include "matlab.h" #include <stdio.h> void main(void) { mxArray *x_ptr; mxArray *y_ptr; double *y; double ret; /* Create an mxArray to input into mlfFoo */ x_ptr = mxCreateDoubleScalar(1); /* Call the library initialization function */ testdlllibInitialize(); /* Call the implementation function */ y_ptr = mlfTestdll(x_ptr); /* Call the library termination function */ testdlllibTerminate(); /* The return value from mlfFoo is an mxArray so we must extract the data from it */ y = mxGetPr(y_ptr); ret = *y; /* Print a double precision number*/ printf("The output of foo is %f\n",ret); mxDestroyArray(x_ptr); mxDestroyArray(y_ptr); }
When I build the program, One error occurs:
error C2660: 'mlfTestdll' : function does not take 1 arguments
Please Help Me. 








I 've the same problem with my function parameters !
I already added #include "matlab.h"
but the problem is with parameters as I built a DLL for bwtraceboundary MATLAB function then mlfBwtraceboundary has different parameters from bwtraceboundary I found it in the mcc file mlfBwtraceboundary(int nargout, mxArray** B, mxArray* varargin);
How can I convert int* to mxArray** ??
and I amn't sure of those parameters as in matlab function or not
I used to call it in matlab by
BW = im2bw(I); imshow(BW); dim = size(BW); col = round(dim(2)/2)90; row = min(find(BW(:,col))); boundary = bwtraceboundary(BW,[row, col],'S',8); imshow(I); hold on; plot(boundary(:,2),boundary(:,1),'g','LineWidth',1); BW_filled = imfill(BW,'holes'); boundaries = bwboundaries(BW_filled); for k=1:10 b = boundaries{k}; plot(b(:,2),b(:,1),'g','LineWidth',1); end
now I wrote
mxArray* varargin={height, width}; mxArray** B=labelsOut;int nargout; bwtraceboundarylibInitialize(); boundary = mlfBwtraceboundary(8,B,varargin); bwtraceboundarylibTerminate(); printf("The output of bwtraceboundary is %f\n",boundary);
any one can help me in converting the parameters and passing them ?
Thanks in advance

matlab.h and libmatlb.h are not present in 2011b version.
How can we modify this the code present on link below to 2011b version
http://www.codeproject.com/KB/DLL/MatlabSharedLib.aspx