Click here to Skip to main content
15,893,594 members
Articles / Programming Languages / C++

A class wrapper for Matlab(c) ActiveX Control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (18 votes)
21 Oct 20023 min read 306.8K   3.9K   65  
Eases up the use of the Matlab(c) COM server...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>MatlabEngine.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.18 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>MatlabEngine.h</h1><div class="fragment"><pre>00001 <span class="comment">// MatlabEngine.h: interface for the CMatlabEngine class.</span>
00002 <span class="comment">//</span>
00004 <span class="comment"></span>
00005 <span class="preprocessor">#if !defined(AFX_MATLABENGINE_H__68399C4F_F2D7_4111_B685_0B4778EE6F16__INCLUDED_)</span>
00006 <span class="preprocessor"></span><span class="preprocessor">#define AFX_MATLABENGINE_H__68399C4F_F2D7_4111_B685_0B4778EE6F16__INCLUDED_</span>
00007 <span class="preprocessor"></span>
00008 <span class="preprocessor">#if _MSC_VER &gt; 1000</span>
00009 <span class="preprocessor"></span><span class="preprocessor">#pragma once</span>
00010 <span class="preprocessor"></span><span class="preprocessor">#endif // _MSC_VER &gt; 1000</span>
00011 <span class="preprocessor"></span>
00012 <span class="comment">// you may want to move these includes to your StdAfx.h</span>
00013 <span class="preprocessor">#include &lt;objbase.h&gt;</span>
00014 <span class="preprocessor">#include &lt;comdef.h&gt;</span>
00015 <span class="preprocessor">#include &lt;vector&gt;</span>
00016 
00018 <span class="preprocessor">#define MATLAB_VERSION_6</span>
00019 <span class="preprocessor"></span>
00020 
<a name="l00100"></a><a class="code" href="classCMatlabEngine.html">00100</a> <span class="keyword">class </span><a class="code" href="classCMatlabEngine.html">CMatlabEngine</a>  
00101 {
00102 <span class="keyword">public</span>:
00104 
00105 
00111         <a class="code" href="classCMatlabEngine.html#z1_0">CMatlabEngine</a>(<span class="keywordtype">bool</span> bDedicated = <span class="keyword">false</span>);
00112         <span class="keyword">virtual</span> ~<a class="code" href="classCMatlabEngine.html">CMatlabEngine</a>();
00114 
00116 
00117 
<a name="l00118"></a><a class="code" href="classCMatlabEngine.html#z3_0">00118</a>         <span class="keywordtype">bool</span> <a class="code" href="classCMatlabEngine.html#z3_0">IsInitialized</a>()<span class="keyword"> const      </span>{ <span class="keywordflow">return</span> m_bInitialized;};
00120 
00122 
00123 <span class="preprocessor">#ifdef MATLAB_VERSION_6</span>
00124 <span class="preprocessor"></span>
00128         <span class="keywordtype">bool</span> <a class="code" href="classCMatlabEngine.html#z5_0">IsVisible</a>();
00133         HRESULT <a class="code" href="classCMatlabEngine.html#z5_1">Show</a>(<span class="keywordtype">bool</span> bShow = <span class="keyword">true</span>);
00134 <span class="preprocessor">#endif</span>
00135 <span class="preprocessor"></span>
00136         HRESULT <a class="code" href="classCMatlabEngine.html#z5_2">MinimizeWindow</a>();
00138         HRESULT <a class="code" href="classCMatlabEngine.html#z5_3">MaximiseWidow</a>();
00140         HRESULT <a class="code" href="classCMatlabEngine.html#z5_4">Quit</a>();
00142 
00144 
00145 
00157         HRESULT <a class="code" href="classCMatlabEngine.html#z7_0">Execute</a>( LPCTSTR szCode);
00158 
<a name="l00160"></a><a class="code" href="classCMatlabEngine.html#z7_1">00160</a>         <span class="keyword">const</span> BSTR&amp; <a class="code" href="classCMatlabEngine.html#z7_1">GetResult</a>()<span class="keyword"> const   </span>{       <span class="keywordflow">return</span> m_vResult.bstrVal;};
00161 
00181         HRESULT <a class="code" href="classCMatlabEngine.html#z7_2">PutMatrix</a>( LPCTSTR szName, <span class="keyword">const</span> std::vector&lt;double&gt;&amp; vArray, UINT nRows, UINT nCols);
00182 
00193         HRESULT <a class="code" href="classCMatlabEngine.html#z7_2">PutMatrix</a>( LPCTSTR szName, <span class="keyword">const</span> std::vector&lt;double&gt;&amp; vRealArray, <span class="keyword">const</span> std::vector&lt;double&gt;&amp; vImgArray, UINT nRows, UINT nCols);
00194 
00205         HRESULT <a class="code" href="classCMatlabEngine.html#z7_4">GetMatrix</a>( LPCTSTR szName,  UINT&amp; nRows, UINT&amp; nCols, std::vector&lt;double&gt;&amp; vRealArray, std::vector&lt;double&gt;* pImgArray = NULL);
00206 
00207 
00208 <span class="preprocessor">#ifdef MATLAB_VERSION_6</span>
00209 <span class="preprocessor"></span>
00216         HRESULT <a class="code" href="classCMatlabEngine.html#z7_5">PutString</a>( LPCTSTR szName, LPCTSTR szString);
00217 
00227         HRESULT <a class="code" href="classCMatlabEngine.html#z7_6">GetString</a>( LPCTSTR szName, LPTSTR&amp; szString);
00228 <span class="preprocessor">#endif</span>
00229 <span class="preprocessor"></span>
00230 
00232 
00233 
00234         <span class="keywordtype">void</span> <a class="code" href="classCMatlabEngine.html#z9_0">SetWorkspace</a>(LPCTSTR szWorkspace);
00236 
00238 
00239 
00240         <span class="keywordtype">void</span> <a class="code" href="classCMatlabEngine.html#z11_0">GetLastErrorMessage</a>() <span class="keyword">const</span>;
<a name="l00242"></a><a class="code" href="classCMatlabEngine.html#z11_1">00242</a>         HRESULT <a class="code" href="classCMatlabEngine.html#z11_1">GetLastHResult</a>()<span class="keyword"> const  </span>{       <span class="keywordflow">return</span> m_hr;};
<a name="l00244"></a><a class="code" href="classCMatlabEngine.html#z11_2">00244</a>         <span class="keyword">const</span> VARIANT&amp; <a class="code" href="classCMatlabEngine.html#z11_2">GetLastVResult</a>()<span class="keyword"> const   </span>{       <span class="keywordflow">return</span> m_vResult;};
<a name="l00246"></a><a class="code" href="classCMatlabEngine.html#z11_3">00246</a>         <span class="keyword">const</span> EXCEPINFO&amp; <a class="code" href="classCMatlabEngine.html#z11_3">GetLastExcep</a>()<span class="keyword"> const   </span>{       <span class="keywordflow">return</span> m_excep;};
<a name="l00248"></a><a class="code" href="classCMatlabEngine.html#z11_4">00248</a>         UINT <a class="code" href="classCMatlabEngine.html#z11_4">GetLastArgErr</a>()<span class="keyword"> const              </span>{       <span class="keywordflow">return</span> m_uArgErr;};
00250 
00251 <span class="keyword">protected</span>:
00253 
00254 
00255         <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classCMatlabEngine.html#z13_3">ErrHandler</a>(HRESULT hr, EXCEPINFO excep, UINT uArgErr);
00257         <span class="keywordtype">void</span> <a class="code" href="classCMatlabEngine.html#z13_0">ProcessString</a>( LPCTSTR szName, BSTR&amp; bstrName);
00259         HRESULT <a class="code" href="classCMatlabEngine.html#z13_1">GetMatrixKnownSize</a>( LPCTSTR szName,  UINT nRows, UINT nCols, std::vector&lt;double&gt;&amp; vArray);
00261         HRESULT <a class="code" href="classCMatlabEngine.html#z13_1">GetMatrixKnownSize</a>( LPCTSTR szName,  UINT nRows, UINT nCols, std::vector&lt;double&gt;&amp; vRealArray, std::vector&lt;double&gt;&amp; vImgArray);
00263 
00264 <span class="keyword">private</span>:
00265         <span class="keywordtype">bool</span> m_bInitialized;
00266         BSTR m_bstrWorkspace;
00267 
00268         IDispatch* m_pMtlbDispApp;
00269         
00270         DISPID m_dispid_GetFullMatrix;
00271         DISPID m_dispid_PutFullMatrix;
00272         DISPID m_dispid_Execute;
00273         DISPID m_dispid_MinimizeCommandWindow;
00274         DISPID m_dispid_MaximizeCommandWindow;
00275 <span class="preprocessor">#ifdef MATLAB_VERSION_6</span>
00276 <span class="preprocessor"></span>        DISPID m_dispid_GetCharArray;
00277         DISPID m_dispid_PutCharArray;
00278         DISPID m_dispid_Visible;
00279 <span class="preprocessor">#endif</span>
00280 <span class="preprocessor"></span>        DISPID m_dispid_Quit;
00281 
00282         HRESULT m_hr;
00283         VARIANT m_vResult;
00284         EXCEPINFO m_excep;
00285         UINT m_uArgErr;
00286         DISPPARAMS m_dpNoArgs;
00287 
00288 <span class="comment">// non unicode handling...</span>
00289 <span class="preprocessor">#ifndef _UNICODE</span>
00290 <span class="preprocessor"></span>        <span class="keywordtype">void</span> AllocateBuffer(UINT uSize)
00291         {
00292                 <span class="keywordflow">if</span> (uSize &lt;= m_uBufferSize-1) 
00293                         <span class="keywordflow">return</span>;
00294                 <span class="keywordflow">if</span> (m_pBuffer) 
00295                         <span class="keyword">delete</span>[] m_pBuffer;
00296                 m_pBuffer = <span class="keyword">new</span> WCHAR[m_uBufferSize = uSize+1];
00297         };
00298         WCHAR* m_pBuffer;
00299         UINT m_uBufferSize;
00300 <span class="preprocessor">#endif</span>
00301 <span class="preprocessor"></span>};
00302 
00303 <span class="preprocessor">#endif // !defined(AFX_MATLABENGINE_H__68399C4F_F2D7_4111_B685_0B4778EE6F16__INCLUDED_)</span>
</pre></div><hr><address style="align: right;"><small>Generated on Wed Oct 9 11:24:15 2002 for MatlabEngine by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.18 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions