From: Aditya on 25 Mar 2010 16:42 Hi I am trying to send data from VC++ to MATLAB. So i am calling engine.h. am running the program i am getting a error: Unhandled exception at 0x0001ae30 in data3.exe: 0xC0000005: Access violation and asks me to break the program. I have included the files matrix.h , engine.h. Also i have included the library files such as libeng, libmat and libmx. The program is as follows: #include "stdafx.h" #include "engine.h" #include <iostream> #include <string> #include "matrix.h" int _tmain(int argc, _TCHAR* argv[]) { using std::cout; int * data; const char * t; Engine * ep; if (!(ep = engOpen(NULL))) { cout <<"Matlab not open"; } mxArray *v = NULL; v = mxCreateDoubleMatrix( 1, 1, mxREAL); double *pT = mxGetPr(v); *pT = 3; //the value i want to send actually it has to be array in hex engPutVariable(ep,t, v); mxDestroyArray(v); engClose(ep); return(0); } Thanks
From: James Tursa on 25 Mar 2010 18:11 "Aditya " <adityapatel.2006(a)gmail.com> wrote in message <hoghqq$ao3$1(a)fred.mathworks.com>... > > engPutVariable(ep,t, v); I don't see anywhere that you set t to anything valid. Looks like you are passing an uninitialized pointer to engPutVariable. James Tursa
From: Aditya on 25 Mar 2010 19:05 "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hogn1n$5pr$1(a)fred.mathworks.com>... > "Aditya " <adityapatel.2006(a)gmail.com> wrote in message <hoghqq$ao3$1(a)fred.mathworks.com>... > > > > engPutVariable(ep,t, v); > > I don't see anywhere that you set t to anything valid. Looks like you are passing an uninitialized pointer to engPutVariable. > > James Tursa Hey Actually C Syntax #include "engine.h" int engPutVariable(Engine *ep, const char *name, const mxArray *pm); engPutVariable writes mxArray pm to the engine ep, giving it the variable name name. So i wanted to define the variable in the workspace as t. Also the problem is occurring before the execution of command. Suppose i comment the whole data trasnfer part and i just try to open the engine and close it.. Still it says the same violation error. thanks
From: James Tursa on 25 Mar 2010 19:42 "Aditya " <adityapatel.2006(a)gmail.com> wrote in message <hogq72$nl6$1(a)fred.mathworks.com>... > "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hogn1n$5pr$1(a)fred.mathworks.com>... > > "Aditya " <adityapatel.2006(a)gmail.com> wrote in message <hoghqq$ao3$1(a)fred.mathworks.com>... > > > > > > engPutVariable(ep,t, v); > > > > I don't see anywhere that you set t to anything valid. Looks like you are passing an uninitialized pointer to engPutVariable. > > > > James Tursa > > Hey > > Actually C Syntax > > #include "engine.h" > int engPutVariable(Engine *ep, const char *name, const mxArray > *pm); > engPutVariable writes mxArray pm to the engine ep, giving it the variable name name. > > So i wanted to define the variable in the workspace as t. Then you should have called it like this: engPutVariable(ep,"t", v); > Also the problem is occurring before the execution of command. > Suppose i comment the whole data trasnfer part and i just try to open the engine and close it.. Still it says the same violation error. Not sure what the problem is there. You don't get any message at all, it just crashes? James Tursa
From: Aditya on 26 Mar 2010 02:05
"James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hogscd$pue$1(a)fred.mathworks.com>... > "Aditya " <adityapatel.2006(a)gmail.com> wrote in message <hogq72$nl6$1(a)fred.mathworks.com>... > > "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hogn1n$5pr$1(a)fred.mathworks.com>... > > > "Aditya " <adityapatel.2006(a)gmail.com> wrote in message <hoghqq$ao3$1(a)fred.mathworks.com>... > > > > > > > > engPutVariable(ep,t, v); > > > > > > I don't see anywhere that you set t to anything valid. Looks like you are passing an uninitialized pointer to engPutVariable. > > > > > > James Tursa > > > > Hey > > > > Actually C Syntax > > > > #include "engine.h" > > int engPutVariable(Engine *ep, const char *name, const mxArray > > *pm); > > engPutVariable writes mxArray pm to the engine ep, giving it the variable name name. > > > > So i wanted to define the variable in the workspace as t. > > Then you should have called it like this: > > engPutVariable(ep,"t", v); > > > Also the problem is occurring before the execution of command. > > Suppose i comment the whole data trasnfer part and i just try to open the engine and close it.. Still it says the same violation error. > > Not sure what the problem is there. You don't get any message at all, it just crashes? > > James Tursa Maybe there is a problem in intialisation of the t pointer and it will work .. But the main problem or error even when i comment the data transfer part is the same:Unhandled exception at 0x0001ae30 in data3.exe: 0xC0000005: Access violation and asks me to break the program. So i am not able to understand why? One factor which i think can be that the OS which i have is 64bit where is my Matlab and VC++ are installed in 32 bit.. thanks |