title: How to return XLOPER (Excel Variable) to VBA directly from a c++ dll?
body: <p>I have no idea how to handle XLOPER type variable in VBA. There are plenty of web pages explaining the relationship between Xloper variable , c++ DLL <strong>and</strong> XLL add-in, however i need to  write c++ function in a dll returning a xloper directly to VBA without XLL framework. (No need of User Defined Function since functions from the dll will be called by the VBA code - not by Excel users).  </p>
  
  <p>Indeed i'm coding a Excel VSTO and i need to call c++ code from it. I found that xloper variable are very useful for XLL so i would like to use this variable type in VBA/VB.Net directly. So is it possible? </p>
  
  <ul>
  <li>my guess it that the xloper can be handled using variant type but i don't know how.
  i found this post :<a href="https://stackoverflow.com/questions/4514679/how-can-i-marshall-between-xloper-and-variant">How can I marshall between XLOPER and VARIANT?</a>  but there is no clear answer.</li>
  </ul>
  
  <p>EDIT :</p>
  
  <p>sorry if i wasn't clear , so for instance i made this c++ function receiving a Int from excel and returning the same value plus 5 as a xloper variale to excel.</p>
  
  <pre><code>  _declspec(dllexport) xloper  _stdcall returnInt( int iVal)
   {
   xloper pxlval_ret;
   int a ;
   a =5 + iVal;
  
   pxlval_ret-&gt;xltype = xltypeInt;
   pxlval_ret-&gt;val.w =  a ;
  
   return pxlval_ret;
  }
  </code></pre>
  
  <p>but i don't know how do call it in vba, Is the return variable a VARIANT?</p>