Skip to content

Commit bc01677

Browse files
committed
Slave now loading and unloading with Excel crash
1 parent b9fba7b commit bc01677

File tree

7 files changed

+51
-44
lines changed

7 files changed

+51
-44
lines changed
Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
11
<DnaLibrary Name="Master Add-In" RuntimeVersion="v4.0">
22
<ExternalLibrary Path="Master.dll" LoadFromBytes="true" Pack="true" />
3-
4-
<!--
5-
The RuntimeVersion attribute above allows two settings:
6-
* RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5
7-
* RuntimeVersion="v4.0" - for .NET 4 and 4.5
8-
9-
Additional referenced assemblies can be specified by adding 'Reference' tags.
10-
These libraries will not be examined and registered with Excel as add-in libraries,
11-
but will be packed into the -packed.xll file and loaded at runtime as needed.
12-
For example:
13-
14-
<Reference Path="Another.Library.dll" Pack="true" />
15-
16-
Excel-DNA also allows the xml for ribbon UI extensions to be specified in the .dna file.
17-
See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
18-
-->
19-
203
</DnaLibrary>

MasterSlave/Master/Master.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<Reference Include="System.Xml" />
4545
</ItemGroup>
4646
<ItemGroup>
47-
<Compile Include="Ribbon.cs" />
47+
<Compile Include="SlaveDriver.cs" />
4848
<Compile Include="Properties\AssemblyInfo.cs" />
4949
</ItemGroup>
5050
<ItemGroup>

MasterSlave/Slave/AddIn.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

MasterSlave/Master/Ribbon.cs renamed to MasterSlave/Slave/Ribbon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public Ribbon()
1919

2020
public override string GetCustomUI(string RibbonID)
2121
{
22-
XlCall.Excel(XlCall.xlcMessage, "BANG!!!!");
22+
// XlCall.Excel(XlCall.xlcMessage, "BANG!!!!");
2323
Console.Beep();
2424
Console.Beep();
2525
Console.Beep();

MasterSlave/Slave/Slave.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
<Reference Include="System.Xml" />
4545
</ItemGroup>
4646
<ItemGroup>
47-
<Compile Include="AddIn.cs" />
47+
<Compile Include="SlaveAddIn.cs" />
4848
<Compile Include="Properties\AssemblyInfo.cs" />
49+
<Compile Include="Ribbon.cs" />
4950
</ItemGroup>
5051
<ItemGroup>
5152
<Content Include="Slave-AddIn.dna">

MasterSlave/Slave/SlaveAddIn.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using ExcelDna.Integration;
7+
8+
namespace MasterSlave
9+
{
10+
public class SlaveAddIn : IExcelAddIn
11+
{
12+
public void AutoOpen()
13+
{
14+
Console.Beep();
15+
Console.Beep();
16+
}
17+
18+
public void AutoClose()
19+
{
20+
Console.Beep();
21+
Console.Beep();
22+
Console.Beep();
23+
Console.Beep();
24+
Console.Beep();
25+
Console.Beep();
26+
}
27+
}
28+
}
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
45
using System.Linq;
6+
using System.Reflection;
57
using System.Text;
68
using System.Threading.Tasks;
79
using Microsoft.Office.Interop.Excel;
@@ -12,9 +14,7 @@ public class Class1
1214
{
1315
public static void Main()
1416
{
15-
var process = LoadAndUnload();
16-
process.EnableRaisingEvents = true;
17-
process.Exited += Process_Exited;
17+
LoadAndUnload();
1818
GC.Collect();
1919
GC.WaitForPendingFinalizers();
2020
GC.Collect();
@@ -26,28 +26,35 @@ public static void Main()
2626
private static void Process_Exited(object sender, EventArgs e)
2727
{
2828
var process = (Process)sender;
29+
Console.WriteLine($"Excel exited with code {process.ExitCode}");
2930
Debug.Print($"Excel exited with code {process.ExitCode}");
3031
}
3132

32-
public static Process LoadAndUnload()
33+
public static void LoadAndUnload()
3334
{
34-
var Application = new Application();
35+
var basePath = @"C:\Work\Excel-DNA\Samples\MasterSlave\";
36+
37+
var Application = new Application();
3538
var process = Process.GetProcessesByName("Excel").First();
39+
process.EnableRaisingEvents = true;
40+
process.Exited += Process_Exited;
3641

3742
Debug.Print(Application.Version);
38-
Application.RegisterXLL(@"C:\Work\Excel-DNA\Samples\MasterSlave\Master\bin\Debug\Master-AddIn.xll");
43+
Application.Visible = true;
44+
45+
46+
Application.RegisterXLL(basePath + @"Master\bin\Debug\Master-AddIn.xll");
3947
foreach (AddIn addIn in Application.AddIns2)
4048
{
4149
if (addIn.IsOpen)
4250
Debug.Print($"> {addIn.Name} @ {addIn.Path}");
4351
}
44-
Application.Visible = true;
45-
//Application.Do
46-
//Application.Run("LoadSlave");
47-
//Application.Run("UnloadSlave");
48-
Application.Quit();
52+
53+
// These are macros defined in Master
54+
Application.Run("RegisterSlave");
55+
Application.Run("UnregisterSlave");
4956

50-
return process;
57+
Application.Quit();
5158
}
5259
}
5360
}

0 commit comments

Comments
 (0)