|
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 h-file'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<br />
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 re-add 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 m-file
|
|
|
|
|
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 M-file?
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 <enter>.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; i<sv->depth; 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 c-mex 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.
|
|
|
|
|
I have a dll. it is OK in C/C++ and LABView.
now i'm trying to call dll from Matlab.
loading and unloading are oke!!
the dll is test.dll and header is test.h
test.h's content is:
extern "C" int PASCAL EXPORT Driver(void ** hDev);
M-file in Matlab
loadlibrary('test','test.h');
libfunctions test -full
arg = libpointer('voidPtrPtr');
%calllib('test','Driver',arg);
unloadlibrary('test');
---
when i use as above. It gives the warning message:
------------------------------------------------------------------------
Segmentation violation detected at Wed Aug 30 15:25:54 2006
------------------------------------------------------------------------
Configuration:
MATLAB Version: 7.0.1.24704 (R14) Service Pack 1
MATLAB License: 253616
Operating System: Microsoft Windows XP
Window System: Version 5.1 (Build 2600)
Processor ID: x86 Family 6 Model 6 Stepping 5, GenuineIntel
Virtual Machine: Java 1.4.2_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
(mixed mode)
Default Charset: ibm-5348_P100-1997
Register State:
EAX = ffffffff EBX = 108dbfb0
ECX = ffffffff EDX = 79b32664
ESI = 0f72e508 EDI = 00cddc0c
EBP = 00cddbe4 ESP = 00cddbe0
EIP = 788dc2d2 FLG = 00010286
Stack Trace:
[0] udd.dll:public: class UDInterface * __thiscall UDInterface::getReference(void)(0xffffffff, 0x108db6d0 "test", 0x00cddfa0, 0x108db830 "Driver") + 2 bytes
[1] libmwcli.dll:void __cdecl CallLibFunction(char *,char *,int,struct mxArray_tag * * const,int,struct mxArray_tag const * * const)(0x108db6d0 "test", 0x108db830 "Driver", 1, 0x00cddf38) + 572 bytes
[2] libmwcli.dll:_mfCallLib(0, 0x00cddf38, 4, 0x108db6d0 "test") + 142 bytes
[3] m_dispatcher.dll:public: virtual void __thiscall Mfh_builtin<struct mxarray_tag="">::dispatch_mf(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cddf38, 4, 0x00cddf98) + 55 bytes
[4] m_dispatcher.dll:public: virtual void __thiscall Mfh_MATLAB_fn::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cddf38, 4, 0x00cddf98) + 200 bytes
[5] m_interpreter.dll:int __cdecl mdDispatch(int,char const *,int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_MATLAB_fn * *)(136, 0x014a0545 "calllib", 0, 0x00cddf38) + 88 bytes
[6] m_interpreter.dll:_inDispatchFromStack(136, 0x014a0545 "calllib", 0, 4) + 801 bytes
[7] m_interpreter.dll:_inCallFcnFromReference(0, 0x108dd070, 0x789b6a50, 0xcccccccd) + 176 bytes
[8] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *)(1, 0, 9, 0) + 4160 bytes
[9] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *)(1, 0, 1, 0) + 272 bytes
[10] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x0f6a39a0, 1, 0, 0x7893a5a0) + 778 bytes
[11] m_interpreter.dll:_inExecCompScript(0, 0x00cde6ac, 0x0f6a39a0, 0xffffffff) + 327 bytes
[12] m_interpreter.dll:public: void __thiscall Mfh_mp::inRunMP(int,struct mxArray_tag * *,int,struct mxArray_tag * *,struct inWorkSpace_tag *)(0, 0x00cde6ac, 0, 0x00cde70c) + 122 bytes
[13] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0, 0x00cde6ac, 0) + 28 bytes
[14] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cde6ac, 0, 0x00cde70c) + 26 bytes
[15] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cde6ac, 0, 0x00cde70c) + 273 bytes
[16] m_interpreter.dll:int __cdecl mdDispatch(int,char const *,int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_MATLAB_fn * *)(480, 0x012d66c4 "Untitled", 0, 0x00cde6ac) + 88 bytes
[17] m_interpreter.dll:_inDispatchFromStack(480, 0x012d66c4 "Untitled", 0, 0) + 801 bytes
[18] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x012d66c4 "Untitled", 480, 0, 0) + 138 bytes
[19] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *)(2, 0, 0, 0) + 2359 bytes
[20] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *)(2, 0, 0, 0) + 272 bytes
[21] m_interpreter.dll:_inInterPcode(2, 0x78773d54, 0, 0) + 69 bytes
[22] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_eval_function(int *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDebugCheck)(0x00cdf2c8, 0x00cdf3b4, 2, 1) + 162 bytes
[23] m_interpreter.dll:$L73181(0x78773d54, 0x0f71e010 "Untitled\n", 0, 0) + 196 bytes
[24] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalCmdWithLocalReturnandtype(char const *,int *,enum inDebugCheck)(0x0f71e010 "Untitled\n", 0, 2, 0x00cdf444 "ôôÍ") + 69 bytes
[25] m_interpreter.dll:_inEvalCmdNoEnd(0x0f71e010 "Untitled\n", 0x00cdf4e4, 0x00cdf49c, 0x014a7f38) + 16 bytes
[26] bridge.dll:_mnParser(0x77e79f93, 0x014a7f38, 0, 0) + 431 bytes
[27] mcr.dll:public: void __thiscall mcrInstance::mnParser(void)(271244, 0x4d5c3a43, 0x414c5441, 0x31303742) + 87 bytes
[28] MATLAB.exe:0x00401d2f(4194304, 0, 271244, 0x014a7f38)
[29] MATLAB.exe:0x00403e45(0, 1, 0x7ffdf000, 0xfb76ecf4)
[30] kernel32.dll:0x77e7eb69(0x00403cc0 "jth8U@", 0, 0, 0)
Please follow these steps in reporting this problem to The MathWorks so
that we have the best chance of correcting it:
1. Send this crash report to segv@mathworks.com for automated analysis.
For your convenience, this information has been recorded in:
E:\DOCUME~1\NGUYEN~1\LOCALS~1\Temp\matlab_crash_dump.956
2. Also, if the problem is reproducible, send the crash report to
support@mathworks.com along with:
- A specific list of steps that will reproduce the problem
- Any M, MEX, MDL or other files required to reproduce the problem
- Any error messages displayed to the command window
A technical support engineer will contact you with further information.
Thank you for your assistance. Please save your workspace and restart
MATLAB before continuing your work.
Error in ==> Untitled at 5
calllib('test','Driver',arg)
----
Where is my error???
----
Help please!
Thanks
-- modified at 21:52 Wednesday 30th August, 2006
|
|
|
|
|
Hi vnc_cp
I am having the same problem, have you managed to fix it?
Rad
|
|
|
|
|
salam,omidvaram haletoon khoob bashe
ye soal daram.
ma baraye anjam projei niaz be yek mohite 3D pishrafte darim ke khaly sari bashe,az tarafi in mohit bayad betoone ba matlab tabadole etelaat kone,in mohite 3D ro man ba "Ogre"(ogre 3D engine:www.Ogre3D.org)neveshtam(be zaboon VC++ 2005)valy nemidoonam chetor mishe in barname ro be function hai ke dar MATLAB neveshte shode mortabet kard.
be nazare shoma rahi hast ke beshe inkaro kard?
mitoonam dar inbare ba shoma betore telephini sohbat konam?(khaly mamnoon misham)
khaly mamnoon
---------------------
Kamran Bigdely bsc of bioMedical Eng. ,AMIR KABIR UNIV.(polytechics of tehran)
bioMedical Eng. bsc
bioMedical Eng. bsc
|
|
|
|
|
Salam,
The easiest method is using MATLAB engine APIs (see my article[^]).
Best regards,
A. Riazi
|
|
|
|
|
Hi Everyone,
I am making an attempt to use the "mexGetArray" function to access array variables. The code is below. It's been picked up from one of the online documents, no major changes have been made.
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *A_ptr;
double *pr;
int num_elements, k;
A_ptr = mexGetArray("A", "base"); /* A defined in current Matlab workspace.*/
num_elements = mxGetM(A_ptr) * mxGetN(A_ptr);
pr = mxGetPr(A_ptr);
pr++;
for(k=2; k<num_elements; k++)
="" *="" k="" loop="" complete,="" does="" not="" show="" here,="" no="" idea="" why=""
="" {
="" *pr="*(pr-1)" +="" *(pr+1);
="" pr++;
="" }
="" mexputarray(a_ptr,="" "base");
}
i="" get="" the="" following="" errors.=""
="">> mex online_e.c
lcc preprocessor error: online_e.c:13 Disagreement in number of macro arguments
lcc preprocessor error: online_e.c:23 Disagreement in number of macro arguments
lcc preprocessor warning: online_e.c:24 No newline at end of file
Error online_e.c: 13 operands of = have illegal types `pointer to incomplete struct mxArray_tag defined at C:\Program Files\MATLAB71\extern\include\matrix.h 144' and `int'
Error online_e.c: 24 illegal character `\032'
4 errors, 1 warnings
C:\PROGRAM FILES\MATLAB71\BIN\MEX.PL: Error: Compile of 'online_e.c' failed.
Can anyone please shed some light on this? Thanks in advance.
Thank you,
Nanda
-- modified at 18:15 Wednesday 12th July, 2006
|
|
|
|
|
Mr. Riazi (or anyone):
I don't understand how you created the GenericDll.h file as it is not even part of the Microsoft Visuall C++ Project file (I am running MVC++.NET VErsion 2003). Why did you add that this header file as you already have the 'MatlabGenericDll.h'? Surely you would want to load the 'MatlabGenericDll.h' as oppose to this 'GenericDll.h'?
Please help...
Regards,
Reddy
-- modified at 11:22 Friday 7th July, 2006
|
|
|
|
|
Hi,
I like to give you a great thanks, you are doing a wonderful job.
I use your example and manage to solve my problem, now i see it, it was quite easy, just copy, paste and modify a little.
I wanted to think too difficult.
You deserve an A and a big hug
|
|
|
|
|