Skip to content

Commit

Permalink
Slave now loading and unloading with Excel crash
Browse files Browse the repository at this point in the history
  • Loading branch information
govert committed Feb 24, 2016
1 parent b9fba7b commit bc01677
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 44 deletions.
17 changes: 0 additions & 17 deletions MasterSlave/Master/Master-AddIn.dna
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
<DnaLibrary Name="Master Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="Master.dll" LoadFromBytes="true" Pack="true" />

<!--
The RuntimeVersion attribute above allows two settings:
* RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5
* RuntimeVersion="v4.0" - for .NET 4 and 4.5

Additional referenced assemblies can be specified by adding 'Reference' tags.
These libraries will not be examined and registered with Excel as add-in libraries,
but will be packed into the -packed.xll file and loaded at runtime as needed.
For example:

<Reference Path="Another.Library.dll" Pack="true" />

Excel-DNA also allows the xml for ribbon UI extensions to be specified in the .dna file.
See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
-->

</DnaLibrary>
2 changes: 1 addition & 1 deletion MasterSlave/Master/Master.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Ribbon.cs" />
<Compile Include="SlaveDriver.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
12 changes: 0 additions & 12 deletions MasterSlave/Slave/AddIn.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Ribbon()

public override string GetCustomUI(string RibbonID)
{
XlCall.Excel(XlCall.xlcMessage, "BANG!!!!");
// XlCall.Excel(XlCall.xlcMessage, "BANG!!!!");
Console.Beep();
Console.Beep();
Console.Beep();
Expand Down
3 changes: 2 additions & 1 deletion MasterSlave/Slave/Slave.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddIn.cs" />
<Compile Include="SlaveAddIn.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Ribbon.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Slave-AddIn.dna">
Expand Down
28 changes: 28 additions & 0 deletions MasterSlave/Slave/SlaveAddIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelDna.Integration;

namespace MasterSlave
{
public class SlaveAddIn : IExcelAddIn
{
public void AutoOpen()
{
Console.Beep();
Console.Beep();
}

public void AutoClose()
{
Console.Beep();
Console.Beep();
Console.Beep();
Console.Beep();
Console.Beep();
Console.Beep();
}
}
}
31 changes: 19 additions & 12 deletions MasterSlave/TestController/TestController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;
Expand All @@ -12,9 +14,7 @@ public class Class1
{
public static void Main()
{
var process = LoadAndUnload();
process.EnableRaisingEvents = true;
process.Exited += Process_Exited;
LoadAndUnload();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Expand All @@ -26,28 +26,35 @@ public static void Main()
private static void Process_Exited(object sender, EventArgs e)
{
var process = (Process)sender;
Console.WriteLine($"Excel exited with code {process.ExitCode}");
Debug.Print($"Excel exited with code {process.ExitCode}");
}

public static Process LoadAndUnload()
public static void LoadAndUnload()
{
var Application = new Application();
var basePath = @"C:\Work\Excel-DNA\Samples\MasterSlave\";

var Application = new Application();
var process = Process.GetProcessesByName("Excel").First();
process.EnableRaisingEvents = true;
process.Exited += Process_Exited;

Debug.Print(Application.Version);
Application.RegisterXLL(@"C:\Work\Excel-DNA\Samples\MasterSlave\Master\bin\Debug\Master-AddIn.xll");
Application.Visible = true;


Application.RegisterXLL(basePath + @"Master\bin\Debug\Master-AddIn.xll");
foreach (AddIn addIn in Application.AddIns2)
{
if (addIn.IsOpen)
Debug.Print($"> {addIn.Name} @ {addIn.Path}");
}
Application.Visible = true;
//Application.Do
//Application.Run("LoadSlave");
//Application.Run("UnloadSlave");
Application.Quit();

// These are macros defined in Master
Application.Run("RegisterSlave");
Application.Run("UnregisterSlave");

return process;
Application.Quit();
}
}
}

0 comments on commit bc01677

Please sign in to comment.