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 and 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).
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?
- my guess it that the xloper can be handled using variant type but i don't know how. i found this post :How can I marshall between XLOPER and VARIANT? but there is no clear answer.
EDIT :
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.
_declspec(dllexport) xloper _stdcall returnInt( int iVal)
{
xloper pxlval_ret;
int a ;
a =5 + iVal;
pxlval_ret->xltype = xltypeInt;
pxlval_ret->val.w = a ;
return pxlval_ret;
}
but i don't know how do call it in vba, Is the return variable a VARIANT?
finally I read attentively the book "Excel Add-in Development in C / C++, 2nd Edition by Steve Dalton". It answers the question and provides source code for it. If you want to perform this operation you need to create a xloper wrapper, the xloper_to_v function which is par of xloper.cpp of the aforementioned book do this job. Due to copyrights, I can't publish here the whole code but just some lines of codes; i think it can give some useful insight: