Loading C/C++ DLLs through ExcelDNA

505 views
Skip to first unread message

Ozzie

unread,
Jul 22, 2009, 4:38:27 AM7/22/09
to ExcelDna
Hi,

Does anyone have an example that shows how to do this?

Ozzie

Govert van Drimmelen

unread,
Jul 24, 2009, 1:13:11 PM7/24/09
to ExcelDna
Hi Ozzie,

There are different ways to go about this, depending on how you want
the C++ libraries to look.
- One way is to make an interface in C# that implements the Excel
integration, and keeping .Net out of the the C++ library. In this case
you'd make a C# class (either in a .dll or just as text in a .dna
file) that using P/Invoke with the [DllImport] attribute to talk to
your native C/C++ functions. The C# class can then contain any
parameter handling you need, as well as the function and argument help
strings and the like. So your C/C++ library stays as a native
calculation library.
- Another approach is to make a .Net .dll using the C++/CLR support in
Visual Studio. You can make .Net libraries in C++, and seamlessly
combine native code and libraries - selecting Visual C++ -> CLR ->
Class Library from the New Project wizard gets you started. The
function would look something like this:

#pragma once
using namespace System;
namespace CPPTest {

public ref class Class1
{
public:
static double AddThemInCPP(double d1, double d2)
{
return d1 + d2;
}
};
}

You compile to a .dll and use with ExcelDna as you would use a
C# .dll, with an ExternalLibrary entry in your .dna file.

Hope this makes sense.

--Govert--

evoXBRZ

unread,
Apr 28, 2014, 3:23:33 AM4/28/14
to exce...@googlegroups.com
Hi Govert;
Apologies for bringing up this very old thread.
I have followed as per your instructions below about Class Libraries [CLR].

My sample C++ dll can be called from excel-DNA (0.30 32-bit) as per your instructions {Class Library CLR].
Consequently, these C++ functions can be called in the Excel GUI via the ExcelDNA xll file.

However the inputs/outputs can only be scalars ie single parameters

When i use std::vector<double> for either input or output
i.e.
std::vector<double>Get_Array(std::vector<double>x)
{
//...
std::vector<double> output;
return output;
}
the function above fails to register in ExcelDNA VB project.

Could you point me in the right direction how to modify your simple example below to allow for array input / output ? (ie STL's vector container ie std::vector<double>)
?

I am using Visual Studio 2010

thank you.

rgds;

Govert van Drimmelen

unread,
Apr 28, 2014, 9:22:42 AM4/28/14
to <exceldna@googlegroups.com>
Hi,

Do you mean you're using C++/CLR to make a managed assembly in C++ that you then export from Excel-DNA?

I suspect you'll need to use the cli::array types to use managed arrays.

-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at http://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages