
Comments and Discussions



This is what I added to the demo code in InitInstance:
glob_pMatlab = new CMatlabEngine;
if (!glob_pMatlab>IsInitialized()) {
::MessageBox(NULL,"Can't initialize MATLAB","Fatal Error!",MB_OK);
return FALSE;
}






Is the sample available in C#?
This sample works, but when I add the Reference in a Project and call mlapp.Execute("..."); I get the exception QueryInterface for interface MLapp.DIMLapp failed.
Why?
Laszlo Sragner





sragner wrote:
Is the sample available in C#?
No, you can write it...
sragner wrote:
when I add the Reference in a Project and call mlapp.Execute(".
? what do you mean ?
Jonathan de Halleux.





My filter is a sixth order bessel low pass filter.
Here is the matlab code.
function filter
clear all;
a=[10395];
wo=1/(23.43e6)
b=[1*(wo^6) 21*(wo^5) 210*(wo^4) 1260*(wo^3) 4725*(wo^2) 10395*(wo) 10395];
c=tf(a,b)
h=c2d(c,1/52.32e6,'tustin')
bode(h)
I wrote the same code in VC++
/*******************************************************************************************
Transfer function:
10395

6.045e045 s^6 + 2.974e036 s^5 + 6.968e028 s^4
+ 9.796e020 s^3 + 8.607e012 s^2
+ 0.0004437 s + 10395
Transfer function:
0.02651 z^6 + 0.1591 z^5 + 0.3977 z^4 + 0.5302 z^3
+ 0.3977 z^2 + 0.1591 z + 0.02651

z^6 + 0.1852 z^5 + 0.4568 z^4 + 0.01633 z^3
+ 0.03876 z^2  0.0007527 z + 0.0003637
Sampling time: 1.9113e008
********************************************************************************************/
unsigned char bessel(unsigned char x) // Function accessible only from this file
{
double b0=0.02651,b1=0.1591,b2=0.3977, b3=0.5302, b4=0.3977, b5=0.1591, b6=0.02651;
double a1= 0.1852, a2= 0.4568, a3= 0.01633, a4= 0.03876, a5= 0.0007527, a6= 0.0003637;
double temp_x1,temp_x2,temp_x3,temp_x4,temp_x5,temp_x6,temp_x7;
double temp_y1,temp_y2,temp_y3,temp_y4,temp_y5,temp_y6;
double y;
unsigned char y_unsigned;
double static xn_1,xn_2,xn_3,xn_4,xn_5,xn_6;
double static yn_1,yn_2,yn_3,yn_4,yn_5,yn_6;
temp_x1 = x * b0;
temp_x2 = xn_1* b1;
temp_x3 = xn_2 * b2;
temp_x4 = xn_3 * b3 ;
temp_x5 = xn_4 * b4;
temp_x6 = xn_5 * b5;
temp_x7 = xn_6 * b6;
temp_y1 = yn_1 * a1;
temp_y2 = yn_2* a2;
temp_y3 = yn_3 * a3;
temp_y4 = yn_4 * a4 ;
temp_y5 = yn_5 * a5;
temp_y6 = yn_6 * a6;
y = temp_x1 + temp_x2 + temp_x3 + temp_x4 + temp_x5 + temp_x6 + temp_x7 + temp_y1 + temp_y2 + temp_y3 + temp_y4 + temp_y5 + temp_y6 ;
xn_6 = xn_5;
xn_5 = xn_4;
xn_4 = xn_3;
xn_3 = xn_2;
xn_2 = xn_1;
xn_1 = (double) x;
yn_6 = yn_5;
yn_5 = yn_4;
yn_4 = yn_3;
yn_3 = yn_2;
yn_2 = yn_1;
yn_1 = y;
y_unsigned = (unsigned char) y;
return y_unsigned;
}
I am working with an experimental platform and filtering is one of the applications of it.
What i am looking for,is to get my matlab plot function when i run the code,after i have done suitable routine and created libraries( you are the specialist).
I hope i'am not too confusing.Please let me know if you need more explanation,or i can send you my code to check if you have some time.
From you name,i can deduce you might be a french speaker
Thx
F.K





flora_k wrote:
I wrote the same code in VC++
Where is it ?
flora_k wrote:
you might be a french speaker
Yes indeed.
Btw, you're bessel function looks strange to me: you are usingt a lot of uninitialized parameters;..
Jonathan de Halleux.





I put the code on the previous message. i just copy/paste it.
All the parameters have been initialized. i think it's a good idea i give you the insight of the whole thing. There we go
// CPPAnalyzerTestModule.cpp : Implementation of CPPAnalyzerTestModule
#include "stdafx.h"
#include "PPAnalyzerTestModule.h"
#include "CPPAnalyzerTestModule.h"
#include "StrDef.h"
// for filter function
#include
#include
//for matlab interfacing
#include
#include "myfunctions.h"
#define BUFSIZE 256
Engine*ep;
mxArray *A_ptr;
double *A;
/////////////////////////////////////////////////////////////////////////////
// CPPAnalyzerTestModule
// handlers used by this module
PPHANDLER_IMPLEMENT_USAGE(PPLogHandler)
PPHANDLER_IMPLEMENT_USAGE(PPErrorHandler)
// imported command id's from other module classes to use PPCMD() macros
#define IMPORT_MODULECOMMANDS
#include "PPChainLib\CmdMap.h"
#include "PPProxyLib\CmdMap.h"
/* TODO: Add #includes for other module classes used:
#include "PPSomeModule\CmdMap.h"
#include "PPOtherModule\CmdMap.h"
... or delete the entire IMPORT_MODULECOMMANDS section if not needed */
#undef IMPORT_MODULECOMMANDS
// function prototypes
void Filter(long amount, unsigned char* pData);
unsigned char bessel(unsigned char x);
// 
// CONSTRUCTOR/DESTRUCTOR
//##ModelId=3B6171AE006E
CPPAnalyzerTestModule::CPPAnalyzerTestModule()
{
PPHANDLER_START_USAGE(PPLogHandler)
PPHANDLER_START_USAGE(PPErrorHandler)
PPLOG2(COARSE, CHAINMODULES, INF, STR_STARTUP, GetModuleClassName())
InitMatlab();
}
//##ModelId=3B6171AE006F
CPPAnalyzerTestModule::~CPPAnalyzerTestModule()
{
PPLOG2(COARSE, CHAINMODULES, INF, STR_SHUTDOWN, GetModuleClassName())
PPHANDLER_STOP_USAGE(PPErrorHandler)
PPHANDLER_STOP_USAGE(PPLogHandler)
CloseMatlab();
}
// 
// PUBLIC COM INTERFACE METHODS
STDMETHODIMP CPPAnalyzerTestModule::Reset(int *result)
{
// keep functionality of baseclass
return CPPChainModuleBase::Reset(result);
}
//##ModelId=3B6171AE007A
STDMETHODIMP CPPAnalyzerTestModule::SetChainModuleId(long idModule, int *result)
{
// keep functionality of baseclass
return CPPChainModuleBase::SetChainModuleId(idModule, result);
}
//##ModelId=3B6171AE007E
STDMETHODIMP CPPAnalyzerTestModule::Connect(unsigned inputNr, IPPChainModule* pPrevModule, unsigned prevOutputNr, int *result)
{
// keep functionality of baseclass
return CPPChainModuleBase::Connect(inputNr, pPrevModule, prevOutputNr, result);
}
//##ModelId=3B6171AE008C
STDMETHODIMP CPPAnalyzerTestModule::SetParameter(IUnknown* pIUnk, int* result)
{
// extend functionality of baseclass
// following file implements the moduleparameter dispatch switch
#include "ParMap.h"
}
//##ModelId=3B6171AE0091
STDMETHODIMP CPPAnalyzerTestModule::SetCommand(long idDest, long idCmd, __int64 offset, const unsigned char* pData, long amount, int* result)
{
// keep functionality of baseclass
return CPPChainModuleBase::SetCommand(idDest, idCmd, offset, pData, amount, result);
}
//##ModelId=3C6D24A501D3
STDMETHODIMP CPPAnalyzerTestModule::IsEnabled(int *IsEnabled, int *ModuleName, int *result)
{
// keep functionality of baseclass
return CPPChainModuleBase::IsEnabled(IsEnabled, ModuleName, result);
}
//##ModelId=3B6171AE009F
STDMETHODIMP CPPAnalyzerTestModule::Validate(int* result)
{
// extend functionality of base class
*result = PP_OK;
HRESULT hr = CPPChainModuleBase::Validate(result);
if (SUCCEEDED(hr) && (*result == PP_OK))
{
// TODO: Add code here for further validation
}
return hr;
}
//##ModelId=3B6171AE00A9
STDMETHODIMP CPPAnalyzerTestModule::Prepare(int* result)
{
// extend functionality of base class
*result = PP_OK;
HRESULT hr = CPPChainModuleBase::Prepare(result);
if (SUCCEEDED(hr) && (*result == PP_OK))
{
}
return hr;
}
//##ModelId=3B6171AE00AC
STDMETHODIMP CPPAnalyzerTestModule::Run(int* result)
{
// keep functionality of baseclass
return CPPChainModuleBase::Run(result);
}
//##ModelId=3C8F773300EF
STDMETHODIMP CPPAnalyzerTestModule::HandleEvent(eModuleEventType eventType, int * result)
{
// keep functionality of baseclass
return CPPChainModuleBase::HandleEvent(eventType, result);
}
//##ModelId=3B6171AE00AF
STDMETHODIMP CPPAnalyzerTestModule::Pull(unsigned outputNr, long amount, long *amountActual, unsigned char* pData, unsigned char * ppCmds, int *more, int *result)
{
HRESULT hr = S_OK;
// replace functionality of baseclass
PullEntry(outputNr, amount, amountActual, pData, ppCmds, more, result);
if (*result == PP_OK)
{
// the main thing: read from previous module
hr = PullPrevModule(0, amount, amountActual, pData, ppCmds, more, result);
if (SUCCEEDED(hr) && (*result == PP_OK))
{
// command preprocessing
PullTransposeCmds(ppCmds, amountActual, pData); // TODO: override if necessary
PullInsertCmds(ppCmds, amountActual, pData);
// a basic loop for command processing
CCmdIterator iter(ppCmds);
CCommand *pCmd;
while (!iter.Ready() && (*result == PP_OK) && *more)
{
if ((pCmd = iter.GetNextCmdForMe(GetChainModuleId())) != NULL)
{
HandleCommand(pCmd, amountActual, pData, more, result);
if (!pCmd>IsBroadcastCmd())
delete pCmd;
}
}
}
/*
Process the data in this block
*/
// call your function
// use number of samples (amount actual)
// use buffer :
// yourfunc(long samples, unsigned char* pData);
//DisplayMatlab(*amountActual, pData, 0);
//FilterInMatlab(*amountActual, pData);
//either
//Filter(*amountActual, pData);
DisplayMatlab(*amountActual, pData, 1);
/*
Process the data in this block
*/
}
PullExit(outputNr, amount, amountActual, pData, ppCmds, more, result);
return hr;
}
//##ModelId=3BB850280291
STDMETHODIMP CPPAnalyzerTestModule::GetRunTimeInfo(const char* name, char* value, int maxlen, int* result)
{
// extend functionality of baseclass
// following file implements the runtimeinfo dispatch switch
#include "RtiMap.h"
}
STDMETHODIMP CPPAnalyzerTestModule::LogDumpRunTimeInfo(int* result)
{
// extend functionality of baseclass
// following lines implement the logdump of all runtimeinfo
#define LOGDUMP_MODULERUNTIMEINFO
#include "RtiMap.h"
#undef LOGDUMP_MODULERUNTIMEINFO
}
//##ModelId=3B61838B030A
STDMETHODIMP CPPAnalyzerTestModule::Abort(int* result)
{
// keep functionality of baseclass
return CPPChainModuleBase::Abort(result);
}
// 
// OVERRIDEABLE METHODS
//##ModelId=3B6171AE0070
const char *CPPAnalyzerTestModule::GetModuleClassName() const
{
// override functionality of baseclass
return STR_MODULECLASSNAME;
}
//##ModelId=3BF1480F01AA
void CPPAnalyzerTestModule::HandleCommand(CCommand *pCmd, long *amountActual, unsigned char *pData, int* more, int *result)
{
// extend functionality of baseclass
// following file implements the commandhandler dispatch switch
#include "CmdMap.h"
}
// 
// MODULEPARAMETER METHODS
// TODO: replace with your own module parameters
//##ModelId=3B6171AE00C9
int CPPAnalyzerTestModule::SetExampleParam(long value)
{
if (value < 0) // is just an example
{
PPERROR2(STR_ERR_EXAMPLEPARAM, GetModuleClassName())
PPLOG2(COARSE, CHAINMODULES, ERR, STR_ERR_EXAMPLEPARAM, GetModuleClassName())
return PP_NOT_OK;
}
m_ExampleParam = value;
return PP_OK;
}
// 
// MODULERUNTIMEINFO METHODS
// TODO: replace with your own module runtime info
//##ModelId=3BF1480F00DF
int CPPAnalyzerTestModule::GetExampleInfo(char* value, int maxlen) const
{
// return example info
static long exampleInfo = 0;
_snprintf(value, maxlen, "ExampleInfo: %ld", exampleInfo++); // is just an example
return PP_OK;
}
// 
// MODULECOMMAND METHODS
// TODO: replace with your own module commands
//##ModelId=3BF1480F01D9
int CPPAnalyzerTestModule::HandleSetByteExample(CCommand *pCmd, long *amountActual, unsigned char *pData, int* more)
{
// set byte to 0xee on offset location
pData[pCmd>GetOffset()] = 0xee; // is just an example
return PP_OK;
}
/*******************************************************************************************
Transfer function:
10395

6.045e045 s^6 + 2.974e036 s^5 + 6.968e028 s^4
+ 9.796e020 s^3 + 8.607e012 s^2
+ 0.0004437 s + 10395
Transfer function:
0.02651 z^6 + 0.1591 z^5 + 0.3977 z^4 + 0.5302 z^3
+ 0.3977 z^2 + 0.1591 z + 0.02651

z^6 + 0.1852 z^5 + 0.4568 z^4 + 0.01633 z^3
+ 0.03876 z^2  0.0007527 z + 0.0003637
Sampling time: 1.9113e008
********************************************************************************************/
unsigned char bessel(unsigned char x) // Function accessible only from this file
{
double b0=0.02651,b1=0.1591,b2=0.3977, b3=0.5302, b4=0.3977, b5=0.1591, b6=0.02651;
double a1= 0.1852, a2= 0.4568, a3= 0.01633, a4= 0.03876, a5= 0.0007527, a6= 0.0003637;
double temp_x1,temp_x2,temp_x3,temp_x4,temp_x5,temp_x6,temp_x7;
double temp_y1,temp_y2,temp_y3,temp_y4,temp_y5,temp_y6;
double y;
unsigned char y_unsigned;
double static xn_1,xn_2,xn_3,xn_4,xn_5,xn_6;
double static yn_1,yn_2,yn_3,yn_4,yn_5,yn_6;
temp_x1 = x * b0;
temp_x2 = xn_1* b1;
temp_x3 = xn_2 * b2;
temp_x4 = xn_3 * b3 ;
temp_x5 = xn_4 * b4;
temp_x6 = xn_5 * b5;
temp_x7 = xn_6 * b6;
temp_y1 = yn_1 * a1;
temp_y2 = yn_2* a2;
temp_y3 = yn_3 * a3;
temp_y4 = yn_4 * a4 ;
temp_y5 = yn_5 * a5;
temp_y6 = yn_6 * a6;
y = temp_x1 + temp_x2 + temp_x3 + temp_x4 + temp_x5 + temp_x6 + temp_x7 + temp_y1 + temp_y2 + temp_y3 + temp_y4 + temp_y5 + temp_y6 ;
xn_6 = xn_5;
xn_5 = xn_4;
xn_4 = xn_3;
xn_3 = xn_2;
xn_2 = xn_1;
xn_1 = (double) x;
yn_6 = yn_5;
yn_5 = yn_4;
yn_4 = yn_3;
yn_3 = yn_2;
yn_2 = yn_1;
yn_1 = y;
y_unsigned = (unsigned char) y;
return y_unsigned;
}
void Filter (long amount, unsigned char* pData)
{
long n;
unsigned char y;
for (n=0; n 




What is your question / problem ?
Jonathan de Halleux.





Hello,
Here is my problem; i have a working program in matlab,say a filter. I have a ready made program in VC++ .What i want to do is to call and display my matlab filter in the VC++ code without actually opening a matlab window.
Is this possible with you theory?
I tried the source code, but there seems to be a problem, i keep having errors.
Help please
F.K





flora_k wrote:
What i want to do is to call and display my matlab filter in the VC++ code without actually opening a matlab window.
What do you mean exactly ?
flora_k wrote:
I tried the source code, but there seems to be a problem, i keep having errors.
If you don't give more details, I can't do much. Moreover, I've unsinstalled matlab so I won't be of any help.
Jonathan de Halleux.





Hello,
For the sample program to be provided, could you please indicate which header files and libraries( and their path as well) have to be included in order for the program to be compiled properly?
F.K





The files provided in the "source file" zip.
Jonathan de Halleux.





Hi again,
My question may sound silly,i am new in this. What is the relation ship between your theory and the matlab engine? What i mean is i can not see the C engine routine in your code.
Could you please provide sample of working code with your approach of the problem?
Thx
F.K





There is no C engine with my appraoch, the code is in C++.
I'm using the matlab engine through it's COM interface, without using the mx functions.
I cannot give a working example, check the demo.
Jonathan de Halleux.





Hi,
I am a beginner in this. I know a little about Matlab and not much about VC++.
I would like to call matlab functions from C.
Can somebody give me the exat syntax of mxCreateCharArray?
I mean like an example with specific values of argument ndim and const int *dims.
#include "matrix.h"
mxArray *mxCreateCharArray(int ndim, const int *dims);
The same for mxCreateDoublematrix,mxCreateString etc...
Thx
F.K





I designed this ActiveX module to avoid mx functions... Sorry can't help on that.
Jonathan de Halleux.







mansour_ahmadian wrote:
In documentation you told that GetString allocate memory for the returned value and the user hould take care of clearing the memory. I look at the demo code. it seems there isn't such code in the sample. As i wrong
If you look deeper at the end of GetString you see
{
_bstr_t s(m_vResult);
szString=new TCHAR[s.length()+1];
_tcscpy( szString, (LPCTSTR)s);
}
That's where the copy arises...
Jonathan de Halleux.





i posted this in the visual c++ forum:
hello @all,
i need an instruction which waits until MATLAB will finish it's job.
earlier forum question:
hello @all,
i try to explain what i want / must do :
i have something like this:
i=0;
while(i<5)
{
// reading out a com
// get datasets and process them
// send the processed datasets to MATLAB to get a diagram
// the diagram is seen in my mfcprogram (but came from matlab)
i++;
}
the only problem is the while loop. without these, the program part runs perfectly. however i need a while loop or something like that.
i think, the problem lie in the fact that the program sends the data to matlab and then directly in the code continues to go. possibly different processes run off parallel.
i think i must have something that waits so long, till matlab is ready with the diagram (i tried Sleep(1000) but it do not work).
maybe somebody know, if matlab has got a 'instruction' or if i can make something like a 'queue'.
thank you very much
sunny
i hope you can help me......
sunny






I have been uisng the Matlab engine DLL interface.
Why is it better to use the ActiveX interface?
Are ther any new APIs.
Yosi





I do not pretend this wrapper is better that the engine DLL. Maybe the text of the article is badly written. In fact, the engine dll has more feature that the COM component: eng..., mat... functions, etc...
However, when using the engine dll or mat dll, you link your project with the right libraries and compile it with some Matlab "mex.bat" file. With the COM interface, you don't need to know all that...
Jonathan de Halleux, Belgium.





It is a nice idea to ve a backend Matlab Server, this will ease debuging and avoiding dll problems, besides that u can write pure matlab code rather than using nonfriendly interfaces between primitive types in C/C++ and Matlab . U can also view and process all ur matrices in matlab command window;P.





I have compiled the code in VC++ 6.0 but none of the menu examples work (with Matlab 12). I am trying to use this to write a universal fuzzy logic translator to go from MATLAB .fis files to VC++ executable, but I am having problems understanding the code...any help would be appreciated.
I code so i can frag!





That's strange. Did you initialize COM ? (Coinitialize)
Where's the error ? Does it find the matlab.application ?
If you want help, you better give more details about the bug...
Jonathan de Halleux, Belgium.





I am sorry, now that I read the post again, I believe it was quite rude. Yours is a very nice piece of code and I would like to thank you for your wonderful work.
I am trying to get VC++ to make 2 calls to MAtlab and output the result in a dialog in my VC++ window. I have initialized COM as public in my project file, included MatlabEngine.h and made MatlabEngine.cpp in the project. Here are a couple of lines of code from my program.
void CDemoDlg::OnOK()
{ UpdateData();
CMatlabEngine matlab;
matlab.Execute(_T("fismat=readfis('invpen#2.fis')"));
matlab.Execute(_T("evalfis([0.1;0.3],fismat)"));
m_strforce = matlab.GetResult();
//m_strforce = matlab.Execute(_T("out=evalfis([0.2;0.5],fismat)"));
UpdateData(FALSE); }
m_strforce is of type CString and is the variable assigned to the answer box in my form. I get an MFC error from windows when I run the program with the comments. If i assign m_strforce to matlab.Execute, then I get an answer of 1, no matter what. The fis system calculates a force depending on the two input factors. I believe my confusion comes from the lack of knowledge of COM programming, but if you see any glaring ways to solve this, please le me know.
Thanks again and keep it up!
Madhujit Ghosh
PS: I am running this on Windows XP, Matlab 12 and VC++ 6
I code so i can frag!





laughinglizard wrote:
I am sorry, now that I read the post again, I believe it was quite rude.
No offense...
laughinglizard wrote:
void CDemoDlg::OnOK()
{
UpdateData();
CMatlabEngine matlab;
matlab.Execute(_T("fismat=readfis('invpen#2.fis')"));
matlab.Execute(_T("evalfis([0.1;0.3],fismat)"));
m_strforce = matlab.GetResult();
//m_strforce = matlab.Execute(_T("out=evalfis([0.2;0.5],fismat)"));
UpdateData(FALSE);
}
You are confused about the use GetResult. GetResult returns a COM status message but has nothing to do with Matlab "ans". I advise you to read a little bit about HRESULT to get deeper understanding.
To retreive data from Matlab, you must use GetMatrix or GetString. In your case if evalfis returns a vector or a matrix, use the following to retreive out:
HRESULT hr;
vector out;
UINT m,n;
hr=matlab.GetMatrix( _T("out"), m,n,out);$
if (FAILED(hr))
// something wrong happened... call GetLastErrorMessage to have the error message
matlab.GetLastErrorMessage();
If out is a string, use GetString:
hr=matlab.GetString(_T("out"), m_strForce);
if (FAILED(hr))
// something wrong happened... call GetLastErrorMessage to have the error message
matlab.GetLastErrorMessage();
Jonathan de Halleux, Belgium.





Hi,
First, thanks a lot for your class.
but I found a bug in the demo application. the lines:
.
.
.
break;
case WM_PAINT: < THIS
break; < WITH THIS ONE
case WM_DESTROY:
PostQuitMessage(0);
break; .
.
.
They are eating 100% of CPU. I think that they aren´t neccesary.
The other thing is that I have Matlab 5.2 and it still doesn´t work the GetMatrix method (I receive an Automation server error). Has anybody found a solution for this?
Thanks in advance.





Did you try the latest update ?
Does someone with the 5.2 tried the class ? I have 6.1, so I can't help you
Jonathan de Halleux, Belgium.





Thanks for your reply Jonathan.
Yes, I´m using the last update.
Just waiting to know if someone else has found the same problem with Matlab V5.2.
Thanks in advance.





If there is one instance of Matlab already running, is there a way to retrieve a matrix from that instance? CMatlabEngine creates a new instance of Matlab so data contained in the other instance is not available. Are you aware of any workaround to this problem?
Anyway, thanks for providing us with such a great article
Keep up the good work!
Carlos





Juan Carlos Cobas wrote:
If there is one instance of Matlab already running, is there a way to retrieve a matrix from that instance?
 If it is a classical instance of Matlab running then the answer is no. You cannot connect to this instance by the COM interface. This is documented somewhere but I forgot where. I see a few workaround:
 Save the workspace or only the matrix to a file and load it using Execute.
 Pass the matrix by the clipboard, this needs to be implemented...
 If the instance of Matlab has been started as a COM server, then normally you are working with the same server, so you should have access to this matrix... Of course I didn't check it
Best regards,
Jonathan de Halleux
C'est au pied du mur que l'on voit le mieux le mur.





Thanks so much
Jonathan de Halleux wrote:
If the instance of Matlab has been started as a COM server, then normally you are working with the same server, so you should have access to this matrix... Of course I didn't check it
Yep, I tried it and it does work as expected
Carlos





Damn I'm good !
Jonathan de Halleux, Belgium.





I've just found a little bug.
In your code:
//! Get the latest string result of Execute...
const BSTR& GetResult() const { m_vResult.bstrVal;};
Should be:
//! Get the latest string result of Execute...
const BSTR& GetResult() const {return m_vResult.bstrVal;};
Carlos





Jonathan de Halleux, Belgium.





This is article is just superb, thanks so much!
I’ve found a minor problem though. I'm using MatLab 6.0 and when the engine is constructed, it fails in the following line:
szFunction = OLESTR("Visible");
m_hr = m_pMtlbDispApp >GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_Visible);
if (FAILED(m_hr)) //HERE IT FAILS!!
return;
However, if those lines are commented out, the program seems to work correctly. I wonder if this problem has to do with my system environment (Win2000 SP2/ VC 6.0/ MatLab 6.0) or it’s something else. Any idea?





It is really a strange bug...
I advise to comment out those lines, anyway the function using "Visible" property are not very useful. I think I'll just delete them for the next update.
Jonathan de Halleux, Belgium.





Thanks for the great job!
I can execute the project with VC6.0 and matlab 6.0,but failed with VC6.0 and Matlab 5.3.
Anyone encounter the similar condtion?





I've tried the class on a computer with Matlab 5.3 and it had the same problem
Jonathan de Halleux, Belgium.





For matlab 5.3.I masked the following code in the constructor of CMatlabEngine and the program can work correctly.
// szFunction = OLESTR("GetCharArray");
// m_hr = m_pMtlbDispApp >GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_GetCharArray);
// if (FAILED(m_hr))
// return;
// szFunction = OLESTR("PutCharArray");
// m_hr = m_pMtlbDispApp >GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_PutCharArray);
// if (FAILED(m_hr))
// return;
// szFunction = OLESTR("Visible");
// m_hr = m_pMtlbDispApp >GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_Visible);
// if (FAILED(m_hr))
// return;
I think that the reason is that matlab 5.3 does not support this three methods and FAILED(m_hr) is true, this lead to function exit and result in 'm_bInitialized = false'.
When m_bInitialzed = false, Execuate method will exit FALSE.
ZHANG Yan





That's it! Thanks for finding the bug, I'll update the sources...
Jonathan de Halleux, Belgium.





Hello.
We can use the Execute & Putmatrix functions from vc7.
But getmatrix returns with an exception(
m_hr = GetMatrixKnownSize( tzBuffer, 1,2, vSize);
m_hr=0x80020009)
do you know anything about this bug, or do you have a solution for this problem?
thanx...
Agyklon





I work a lot with Matlab in telecomunications projects and with VC++ for general programming. This will help me join the best of both worlds!
Thanks!!!





GetMatrix is now working, might interrest you.
Jonathan de Halleux, Belgium.





Thanks!





GetString is working also now...
Jonathan de Halleux, Belgium.





chris will be wetting himself  he'll be just dying to try it out
bryce





Matlab  woohoo!
cheers,
Chris Maunder







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.

First Posted  15 Sep 2002 
Views  242,128 
Bookmarked  63 times 

