Host Xll

270 views
Skip to first unread message

RS DID

unread,
Sep 8, 2011, 1:25:55 PM9/8/11
to Excel-DNA
Hi Govert
I have been trying to make use of the code you recently posted
regarding unloading a packed xll inside a host xll.

This call is throwing and exception :

object removeId = XlCall.Excel(XlCall.xlfRegister, name,
"xlAutoRemove", "I", ExcelMissing.Value, ExcelMissing.Value, 2);

where name = @"C:\projects\\XLL\bin\Debug\MyXLL-packed.xll"

Any ideas why this call will throw an exception? I am using VS 2008
and ExcelDna 2.7


Thanks

Rob D.

Govert van Drimmelen

unread,
Sep 8, 2011, 1:29:07 PM9/8/11
to Excel-DNA
Hi Rob,

Your path is wrong - you have a double backslash?

-Govert

RS DID

unread,
Sep 8, 2011, 1:38:16 PM9/8/11
to exce...@googlegroups.com
Actually that is a typo in the email I sent, the code does not have that double back slash. 

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.


Govert van Drimmelen

unread,
Sep 8, 2011, 1:51:09 PM9/8/11
to Excel-DNA
OK - could you start with the .dna file from that post, and with
version 0.29?
That should work fine, then we can try to work back from there.

Whether anything is packed or not shouldn't make a difference, but I
was testing just with two .dna files and matching .xlls.

-Govert

RS DID

unread,
Sep 8, 2011, 2:26:38 PM9/8/11
to exce...@googlegroups.com
Hi Govert
Am I required to use ExcelDNA2.9 to be able to use this code?  I have built my code with ExcelDNA2.9 but now the add in will not load.  There is an error message :

"A problem occurred while an add-in was being initialized (IntializeIntegration failed) This add-in is built with ExcelDna an d is being loaded from ..."

Also want to point out that I am on .NET 3.5.  , Excel 2003 and VS2008

Thanks

Rob D.

RS DID

unread,
Sep 8, 2011, 2:35:39 PM9/8/11
to exce...@googlegroups.com
Sorry for the red herring, I am using the wrong XLL file...   I'll report back soon on the other issue

Govert van Drimmelen

unread,
Sep 8, 2011, 2:38:08 PM9/8/11
to Excel-DNA
Hi Rob,

I don't know whether you need version 0.29 to do the unloading - I
doubt it, but there might have been some relevant changes and I'm not
so keen to support old versions.
So I'm trying to get you to a state where the code that works for me
also works for you - then we can figure out the problem you have
there, whether it is a version issue or whatever.

The InitializeIntegration error you get now is probably due to a
mismatched version of ExcelDna.Integration.dll in your output
directory.
Just delete this file in the output, set the reference to "Copy
Local=false". You never need ExcelDna.Integration.dll in your output
directory, or to redistribute it.

Your .NET, Excel and VS versions are all happily supported by the
latest version of Excel-DNA.

-Govert

RS DID

unread,
Sep 13, 2011, 5:33:43 PM9/13/11
to exce...@googlegroups.com
Hi Govert
I tested the DNA files supplied in this thread, as you suggested, and they worked as advertised.  They load and unload the XLL without errors.  I am using ExcelDNA2.9 with Excel 2003.  I can also report that it worked with a "packed" Xll too.

The loader works in both the DNA example and the C# module.

 When I take the DNA code and put it into VS2008 as C# code, build a DLL,  have a same named DNA and XLL file, I still get a exception thrown on this call.


object removeId = XlCall.Excel(XlCall.xlfRegister, name, "xlAutoRemove", "I", ExcelMissing.Value, ExcelMissing.Value, 2);

my DNA file is simple. 

<DnaLibrary>
    <ExternalLibrary Path=".\HostAddIn.dll" Pack="true" />
</DnaLibrary>


One observation :

After the first exception is caught, if I rerun the XLL unloader code in the same process, it unloads the XLL without error, if I set a break point on this call and try to step through the unload calls, it throws an exception every time. In either case, the first time I call the unload function, it throws an exception on the call above.

Here is the C# code. 

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace HostAddIn
{   
    using ExcelDna.Integration;

    public class HostXLL
    {
        public static object registerId;

        private const String addInToLoad = @"C:\work\AXLL\bin\Debug\AXLL-packed.xll";

        [ExcelCommand(MenuName = "AddinHost", MenuText = "Load Addin")]
        public static void LoadAddin()
        {
            XlCall.XlReturn result = XlCall.TryExcel(XlCall.xlfRegister, out registerId, addInToLoad);
        }

        [ExcelCommand(MenuName = "AddinHost", MenuText = "Unload Addin")]
        public static void UnloadAddin()
        {
            string name = @"C:\work\AXLL\bin\Debug\AXLL-packed.xll";

            MessageBox.Show("About to call xlAutoRemove.");
            try
            {

                object removeId = XlCall.Excel(XlCall.xlfRegister, name, "xlAutoRemove", "I", ExcelMissing.Value, ExcelMissing.Value, 2);

                object removeResult = XlCall.Excel(XlCall.xlfCall, removeId);

                object removeUnregister = XlCall.Excel(XlCall.xlfUnregister, removeId);

                object success = XlCall.Excel(XlCall.xlfUnregister, registerId);
                MessageBox.Show("Result of Unregister: " + success.ToString());
            }
            catch (Exception xllErr)
            {
                string errMsg = xllErr.Message;
                errMsg += (xllErr.InnerException != null  ? Environment.NewLine + xllErr.InnerException.Message : Environment.NewLine + " No inner message ");
                errMsg += (!string.IsNullOrEmpty(xllErr.StackTrace) ? Environment.NewLine + xllErr.StackTrace : Environment.NewLine + " No stack message ");
                MessageBox.Show(errMsg);
            }
        }
    }

    public static class MyFunctions
    {
        public static string AddinHostTestFunction()
        {
            return "Hello from the add-in host!";
        }

        [ExcelCommand(MenuName = "AddinHost", MenuText = "Say Hello!")]
        public static void AddIn()
        {
            MessageBox.Show("Hello from the add-in host!");
        }
    }
}


The error message thrown :

Exception of type 'ExcelDna.Integration.XlCallException' was thrown.
 No inner message
   at ExcelDna.Integration.XlCall.Excel(Int32 xlFunction, Object[] parameters)
   at HostAddIn.HostXLL.UnloadAddin() in C:\Host\HostAddIn\HostAddIn.cs:line 30


Looking for suggestions or another path I can try to determine what is causing this error.

Thanks

Rob D.

Govert van Drimmelen

unread,
Sep 13, 2011, 5:43:48 PM9/13/11
to Excel-DNA
Hi Rob,

Not sure if the two threads are getting intertwined (http://
groups.google.com/group/exceldna/browse_frm/thread/92086ea65e3c1e69),
but on Excel 2002 I had to change that line to

object removeId = XlCall.Excel(XlCall.xlfRegister, name,
"xlAutoRemove", "I", ExcelEmpty.Value, ExcelEmpty.Value, 2);

Maybe that helps you too?

-Govert

RS DID

unread,
Sep 13, 2011, 5:38:37 PM9/13/11
to exce...@googlegroups.com
Hi Govert,

The message you just posted to Andreas , fixed my problem as well.

Excellent and thanks..

Rob D.

RS DID

unread,
Sep 13, 2011, 5:47:49 PM9/13/11
to exce...@googlegroups.com
Hi Govert

It did help, by changing the parameters to ExcelEmpty.Value, the unload of the XLL is now working.  Just for the record, I am using

Excel2003, ExcelDNA2.9, .Net 3.5 and VS2008.

Thanks again
Reply all
Reply to author
Forward
0 new messages