Hi,
You can create managed (CLI) arrays in your C++/CLI code, using the
'array' keyword.
Some more info on C++/CLI arrays here:
http://www.codeproject.com/Articles/7704/Arrays-in-C-CLI
Excel-DNA only supports arrays of type 'Object' or 'double', and
easiest is to use 2D-arrays. The array can be returned directly from
your C++ function - since it is a managed (CLI) array, it will be
garbage collected once Excel has processed it.
So something like this should work (I didn't test it, though):
public ref class MyFunctions
{
public:
static array<double^,2>^ GetCppValues()
{
array<double^,2>^ values = gcnew array<double^,2>(4,2);
values[0,0] = 1.23;
values[1,0] = 2.34;
// ... etc.
return values;
}
}
For strings and other types, use array<Object^,2>^.
> Would XLW be more suited in this instance, since I am using C++. Please
> let me know your views.
Excel-DNA is best for making .NET add-ins for Excel. If you are using C
++ and have no other reason to use .NET, it's probably simpler to not
add it in the mix. Then you'd rather use one of the other C++
solutions: XLW, or
http://xll.codeplex.com, or spend the money and get
XLL+.
See also my answer here:
http://exceldna.codeplex.com/discussions/371219.
-Govert
On Aug 12, 12:42 am, Chintu <
bsnataraj...@gmail.com> wrote:
> > Thanks for the reply.
> > I am using option 3, by directly including the path to the DLL in the .dna
> > file. When you say using 'array references', do you mean passing the array
> > as a (reference) parameter. I didn't think that this could be done when we
> > calling an XLL function directly from Excel. It would be a great help if
> > you could point me to an example as I am quite new to this side of
> > development (calling DLL functions from Excel).
>
> > Would XLW be more suited in this instance, since I am using C++. Please
> > let me know your views.