
Comments and Discussions




Hi,
I've used a function from matlab library (normrand) in order to generate random numbers with normal distribution. Now I'm going to use such function in my program which is in Visual C#. How could I do this?
Is it correct to create a .dll file with c++ compiler and then use ".net framework" procedures to use a C code in my C# program?
In fact creating a .dll file from a matlab .m file is not still clear for me?
Is there anybody who could help me?
Thanks for your cooperation





Hi,
My codes are:
loadlibrary('MatlabGenericDll','GenericDll');
or loadlibrary('MatlabGenericDll','MatlabGenericDll');
Then, matlab compiler (R2009a) responds me:
Could not find file GenericDll.h
or Could not find file MatlabGenericDll.h
Do I need to install some other programs in order to access matlab program from VC++?
Thanks.






hello
I have a function which retrieves an array of double:
EXPORT void GetCurves(char* strYieldCurveName, double * Curves);
The memory should actually be allocated by calling code:
MATLABGENERICDLL_API void GetCurves(char* strName, double * Curve)
{
for(int i=0; i<100; i++)
{
if(i>0) {
Curve[i] = 1.01 * Curve[i1];
} else {
Curve[i] = 0.5;
}
}
return;
}
I tried call this from Matlab, nothing happens  i.e. Curve remains empty.
hfile = ['C:\GenericDll.h'];
loadlibrary('C:\MatlabGenericDll', hfile)
Curve = zeros(1,100);
calllib('MatlabGenericDll', 'GetCurves', 'xyz', Curve)
unloadlibrary MatlabGenericDll
I checked "Curve"  it's all zero's, as though it's been "passed by value".
Any suggestion? Thanks
dev






hi A.Riazi,
This is Madhu Sudhan Reddy Mopuru from India. I am doing a project in which shape matching is required. I found blongie (shape matching) algorithm in Matlab (.m and .mat files) and I don't know much about Matlab. I am using Delphi7. Could you please tell me how to make these .m and .mat files to be used in my project. You have great experience in Pascal and Matlab. Please help me. This algorithm is crucial part of my project.
Thank you
Regards
Madhu Sudhan Reddy Mopuru





Hello there,
I am new here and hope to receive help on my problem.
Currently, I try to invoke a *.dll in Matlab.
The *.dll was made by Visual Studio 2008 (C++  Project).
As a result Visual Studio created a *.dll without a header file.
The Matlab function loadlibrary requires two arguments, the *.dll and the header file.
That brings me to the question, how should the header file looks like and are there any
special requirements building the *.dll to use it in Matlab?
many thanks
Jens





>> loadlibrary('Lusbapi', 'E140.h')
And this warning message's:
Warning: Message from C preprocessor:
lcc preprocessor warning: D:\MATLAB\DLL2\LusbapiTypes.h:106
D:\MATLAB\DLL2\Lusbapi.h:8 D:\MATLAB\DLL2\LUsbBase.h:8
D:\MATLAB\DLL2\E140.h:5 EOF inside comment
lcc preprocessor warning: D:\MATLAB\DLL2\LusbapiTypes.h:106
D:\MATLAB\DLL2\Lusbapi.h:8 D:\MATLAB\DLL2\LUsbBase.h:8
D:\MATLAB\DLL2\E140.h:5 No newline at end of file
lcc preprocessor error: D:\MATLAB\DLL2\LusbapiTypes.h:106
D:\MATLAB\DLL2\Lusbapi.h:8 D:\MATLAB\DLL2\LUsbBase.h:8
D:\MATLAB\DLL2\E140.h:5 Unterminated conditional in #include
lcc preprocessor warning: D:\MATLAB\DLL2\Lusbapi.h:17
D:\MATLAB\DLL2\LUsbBase.h:8 D:\MATLAB\DLL2\E140.h:5 EOF inside comment
lcc preprocessor error: D:\MATLAB\DLL2\Lusbapi.h:17
D:\MATLAB\DLL2\LUsbBase.h:8 D:\MATLAB\DLL2\E140.h:5 Unterminated conditional
in #include
lcc preprocessor error: D:\MATLAB\DLL2\E140.h:165 Unterminated
#if/#ifdef/#ifndef
> In loadlibrary at 270
Warning: Warnings messages were produced while parsing. Check the functions
you
intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary at 279
>>
Whot I do wrong?





I use this dll's and hfile's for my project:
http://www.lcard.ru/download/lusbapi32.exe





Hey guys im getting this error and I am so confused. I have browsed the internet and cannot figure out what the problem is.
[code]
addpath('C:\Program Files\Matlab\Work\DLLTEST')
addpath('C:\Program Files\Matlab\Work\DLLTEST\Debug')
loadlibrary DLLTEST DLLTEST.h addheader nma.h
[code]
> In loadlibrary at 218
In ErikMTF at 14
??? There was an error loading the library "C:\Program Files\MATLAB\R2006a\work\DLLTEST\Debug\DLLTEST.dll"
Error using ==> loaddefinedlibrary
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
Error in ==> loadlibrary at 273
diagnoseError(err);
Error in ==> ErikMTF at 14
loadlibrary DLLTEST DLLTEST.h addheader nma.h
>>
[/code]
Thanks!





salam
man ghablan ham be shoma email zadam
man daneshjuye term akhare narm afzaram va yek poroje daram ke az shoma komak mikham
man bayad yeki az tavabe matlab ro be shekle dll daravorde ta beshe dakhele c ya c# azash estefade kard
lotfan komakam konid
mamnun misham
montazeram
bye





Hi,
I've added the 'Matlab Interface to Generic DLLs' files and added the '\toolbox\matlab\general' folder to the Matlab path:
addpath([matlabroot '\toolbox\matlab\general'])
But if I set my current directory to the folder containing the MatlabGenericDLL files and type:
loadlibrary('MatlabGenericDll', 'GenericDll.h')
I get the following error:
??? Error using ==> calllib
To call a function both the library name and function name are needed.
Can anyone explain this?
(I'm using Matlab 7.4.0  R2007a)
modified on Wednesday, April 2, 2008 4:18 AM





Hmmm  well I uninstalled R2007a and installed R14 of Matlab. Didn't readd the 'Matlab Interface to Generic DLLs' files and I can now call all those library methods (loadlibrary etc) without any errors. Don't have time though to investigate which combination of Matlab and 'Matlab Interface to Generic DLLs' work and which don't work.





I've have this problem,can anyone solve it?






thanks alot for your article.
i wan to integrate matlab with c#
how to do this? and how to create dll for matlab mfile





I've made a simple .dll and built it in both Visual Studio 6.0 (test6.dll) and 7.1 (test7.dll). The dll exports a single function (method) with no arguments.
Using
loadlibrary test6.dll test6.h
goes just fine.
libfunctions test6 full
shows the name of the exported method
However, trying to call the method with the command:
calllib('test6','fnExport')
just give the answer:
Method was not found.
What do I do wrong. Is there any flags I must set before building in Visual studio?
torand





Hi! Can anyone help me?:
How do I call a Matlab dll from a Matlab Mfile?
Thanks
Bonoman





Hi,
I am having the same problem with you, i cant load the library to Matlab.
Can any body help on this?
Thanks.
yeelin





I create a dll in Matlab 7 SP2, but don't register in window.
in DOS prompt, c:\work\regsvr32 propor.dll .After, there is a messenger "propor.dll was loaded, but the dllregisterserver entry point was not found, dllregisterservermay not be exported, or a corrupted version of propor.dll may in memory".
I now used c com, too and is much simple to get a dll (C COM) and so call into VB, but is much slow for to calculate.
Help me Thanks.
Reinaldo Teixeira





Hi there
I am trying to call a matlab DLL from a C++ DLL.
First I created the C++ wrapper file in which Matlab DLL is initialized and called. Then, I generated the DLL from that wrapper file. I have another program that can access the wrapper DLL.
My problem is when that other program calls the wrapper DLL it always fails to initialize the Matlab DLL. I have come across some newsgroup where some people are having the same problems. Do you have any idea why this is ?
Below is sample of my code:
#include "udm.h" // needed for my other program
#include "MyMovingAveragelib.h"
typedef struct
{
double *window;
int depth; // moving average window depth
} STATE_VARIABLE;
int UDM_DLL_EXPORT moving_average()
{
//Declare local variables
double *sum;
int i;
STATE_VARIABLE *SV;
UDMParamValue *parameter;
mxArray *depth;
mxArray *currentsample;
mxArray *window_in=NULL;
mxArray *window_out=NULL;
mxArray *av;
// Always begin with initialization code
if(SudmGetStatus() == SUDM_INIT_STATE)
{
if(!SudmAllocateStateVars(sizeof(STATE_VARIABLE))) return(1);
// Read in the state variables and input parameters
SV = (STATE_VARIABLE *) SudmGetStateVars();
parameter = SudmGetModelParamsEx();
SV>depth = parameter[0].ival;
// Allocate memory for the window and initialize it
SV>window = (double*) malloc(SV>depth * sizeof(double));
for (i=0; idepth; i++)
SV>window[i] = 0.0;
// Free any allocated memory
}
else if(SudmGetStatus()==SUDM_SIM_COMPLETE)
{
SV = (STATE_VARIABLE*) SudmGetStateVars();
free(SV>window);
SudmFreeStateVars();
return(0);
}
// Call the MCR and library initialization functions
if( !mclInitializeApplication(NULL,0) )
return(1);
if (!MyMovingAveragelibInitialize())
return(1);*/
// Read in the stored state variables
SV = (STATE_VARIABLE *) SudmGetStateVars();
//Check if enough samples are at the input buffer(s)
//allocate space for the output sample(s)
if (!SudmEnoughInputSamples(0,1)) return(0);
if (!SudmAllocateOutputBuffer(0,1)) return(0);
// Attempt to Call Matlab DLL
depth = mxCreateDoubleScalar(SV>depth);
currentsample = mxCreateDoubleScalar(SudmGetInputValue(0).r);
window_in = mxCreateDoubleMatrix(1,SV>depth,mxREAL);
window_out = mxCreateDoubleMatrix(1,SV>depth,mxREAL);
memcpy(mxGetPr(window_in),SV>window,SV>depth * sizeof(double));
mlfMyMovingAverage(2,&av,&window_out,window_in,currentsample,depth);
memcpy(SV>window,mxGetPr(window_out),SV>depth * sizeof(double));
sum = (double*)mxGetPr(av);
// Write the moving average to the output
SudmSetOutputValue(0,*sum,0.0);
// Free up the memory
mxDestroyArray(currentsample);
mxDestroyArray(depth);
mxDestroyArray(av);
mxDestroyArray(window_in);
mxDestroyArray(window_out);
// Call the MCR and library termination functions
MyMovingAveragelibTerminate();
mclTerminateApplication();
// Return successfully completed flag
return(0);
}
BEGIN_MODEL_TABLE
FUNCTIONAL_MODEL("MOVAVG", moving_average, 1, "r", 1, "r", \
NO_DATA_REQ, NOT_APPLICABLE, \
"depth.integer.[1,inf)=1, \
RIN=inf, ROUT=0")
END_MODEL_TABLE
Hendry





Dear friend,
I am trying to do the opposite from what you are working in this article. As it is well known is more easier to work with matrixes in MATLAB. So,I want to compile some of my .m scripts through mcc to shared libraries and call them from a main program I wrote in C++. There is an extensive help that comes with MATLAB about this subject but..., I made some attemps and found two annoying things with mcc. The first is that a MATLAB GUI compiled as a stand alone application always open a command prompt window (a console) before opening the GUI itself. Additionally, the first time one uses the .exe file,it took a noticeable amount of time to begin to work. When I tried the shared libraries + C examples I also note a slow response from the final app even in the case where there's only a few of some basic matrix operations. Do you have any experience on this subject that can share with me?. I am trying to avoid the work of making all the matrix and vector simplified treatment of MATLAB to C,...!!, You see, I'm a bit lazy, so please excuse me if I am bothering with this kind question.
Regards,
Mario






Hi !
I've got a huge project, and I want to call it's interface from matlab.
I can wrap it as a generic Dll (as in this article) and i can also wrap it as a cmex file (which will create a "matlab dll").
What is the differences between them ?
Of course, Dll is better because it can be used outside matlab, are there any advantages to "matlab dll"? If not, for what was it created ?
tnx,
buri.







General News Suggestion Question Bug Answer Joke Rant Admin Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Type  Article 
Licence  
First Posted  18 Nov 2003 
Views  307,598 
Bookmarked  42 times 

