title: How MATLAB mex files access MATLAB instances?
body: <p>This is the entry point for every mex file:</p>
  
  <pre><code>void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
  </code></pre>
  
  <p>In fact mex files are windows dll files with mexFunction as the main function.
  My question is when the mex function is called, how it can access matlab instance specific data from inside the mex. As an example, consider 'mexPutVariable' function. It's job is 'copy an array from inside MEX-function into the specified workspace (outside mex)'. But how it knows where is 'workspace'. No parameter has passed to mex (like a pointer), containing matlab instance data (caller). mex files know only nlhs, plhs, nrhs, prhs and none of them can help mex files to excavate matlab instance specific data(caller function information).</p>