Adding multiple DLL

832 views
Skip to first unread message

Rookie

unread,
Aug 31, 2009, 9:54:10 AM8/31/09
to ExcelDna
How do I add multiple Dll under the same add-in in Excel:
Say, I have a project firstProject.DNA, firstProject.XLL and
firstProject.DLL, the .DNA file has the reference to firstProject.DLL
and I load this .XLL as Add-in into Excxel
1) now if I create a secondProject.DLL under a different namespace,
can this DLL be included in the firstProject.DNA along with the
firstProject.DLL copying secondProject.DLL back into the same
directory as the firstProject.DLL. .XLL and .DNA
2) can I use the same XLL i.e. firstProject.XLL or do I need to keep
everything separate?
3) how do I reference functions for separate DLLs in Excel, if the
function names are same in both DLLs do I access it as Application.Run
("firstProject.MyFunc1",param1, param2..) and Application.Run
("secondProject.MyFunc1",param1, param2..)

Govert van Drimmelen

unread,
Sep 1, 2009, 7:46:56 AM9/1/09
to ExcelDna
Hi Rookie,

Each add-in (MyAddIn.xll file) is associated with a MyAddIn.dna file
with the same filename.
In the .dna file you can load multiple .dll projects and other .dna
files, using ExternalLibrary entries.
<DnaLibrary>
<ExternalLibrary Path="FirstProject.dll" />
<ExternalLibrary Path="SecondProject.dll" />
<ExternalLibrary Path="OtherStuff.dna" />
</DnaLibrary>

The .Net namespaces in your projects are not used by ExcelDna at all.
If functions have the same name in different classes (in the same or
different libraries or namespaces), the last function found is the one
that 'wins'. You can set the name used in Excel by adding an
ExcelFunction attribute with a "Name" argument, say
[ExcelFunction(Name="FirstProject.FirstFunction", Description....]
public static string FirstFunction(...)

This function will be called FirstProject.FirstFunction in Excel and
when called from Application.Run in VBA.

Hope this answers your questions.

Regards,
Govert

Rookie

unread,
Sep 1, 2009, 12:47:33 PM9/1/09
to ExcelDna
Thanks, couple of follow up questions:
1)When compiling the first project does the DLL name(or the project
name) has to be same as the XLL and DNA name? i.e. if the first
project is called firstProject and generates a DLL of
firstProject.DLL, does the XLL and DNA file name also has to be
firstProject.XLL and firstProject.DNA or it can be MyAddin.XLL and
MyAddin.DNA and within the DNA file I can point to firstProject.DLL
i.e. it is not necessary that MyAddin.DLL has to exist. If the DLL is
deployed by creating a new folder, can there be only 3 files in that
folder; MyAddin.DNA, MyAddin.XLL and firstProject.DLL; MyAddin.DNA has
firstProject.DLL included as external library.
2)As to your reply using the "Name" argument in ExcelFunction, after
it is included as you described and called from VBA, will it still get
the last function with similar name even though they are in different
DLLs or namespaces? i.e. if I have myFunction1 in firstProject and
secondProject named as ExcelFunction(Name="firstProject.MyFunction1")
and ExcelFunction(Name="secondProject.MyFunction1") can I state as
Application.Run("firstProject.MyFunction1", arg1,arg2....) and
Application.Run("secondProject.MyFunction1", arg1,arg2....) and it
will pickup the respective functions from firstProject and
secondProject?
Thanks in advance for your patience with these basic questions.
> > ("secondProject.MyFunc1",param1, param2..)- Hide quoted text -
>
> - Show quoted text -

Govert van Drimmelen

unread,
Sep 3, 2009, 7:37:50 AM9/3/09
to ExcelDna
Hi,

1. The .dll names that your <ExternalLibrary> etries refer to need not
be the same as you .xll/.dna files names.
2. If you use the ExcelFunction attribute to give a new "Name" to your
functions, they will be registered in Excel under the distinct names,
and will stay separated as in your example.

--Govert--
Reply all
Reply to author
Forward
0 new messages