Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/ExcelDna.ManagedHost/AddInInitialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static short Initialize(void* xlAddInExportInfoAddress, void* hModuleXll,
string tempDirPath = Marshal.PtrToStringUni((IntPtr)pTempDirPath);
_alc = new ExcelDnaAssemblyLoadContext(pathXll, disableAssemblyContextUnload == 0);
AssemblyManager.Initialize((IntPtr)hModuleXll, pathXll, _alc, Path.Combine(tempDirPath, "ExcelDna.ManagedHost"));
AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs args) => AssemblyManager.AppDomainAssemblyResolve(args.Name);
var loaderAssembly = _alc.LoadFromAssemblyName(new AssemblyName("ExcelDna.Loader"));
var xlAddInType = loaderAssembly.GetType("ExcelDna.Loader.XlAddIn");
var initOK = (bool)xlAddInType.InvokeMember("Initialize", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null,
Expand Down
41 changes: 35 additions & 6 deletions Source/ExcelDna.ManagedHost/AssemblyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,49 @@ internal static Assembly AssemblyResolve(AssemblyName assemblyName, bool logMiss
internal static string NativeLibraryResolve(string unmanagedDllName)
{
#if NETCOREAPP
byte[] dllBytes = GetResourceBytes(unmanagedDllName.ToUpperInvariant(), 5);
return ExtractDllResource(unmanagedDllName, unmanagedDllName, 5);
#else
return null;
#endif
}

#if NETCOREAPP && !AOT_COMPATIBLE
[MethodImpl(MethodImplOptions.Synchronized)]
internal static Assembly AppDomainAssemblyResolve(string assemblyName)
{
string dllFileNameWithoutExtension = new AssemblyName(assemblyName).Name;
string dllFileName = dllFileNameWithoutExtension + ".dll";
{
string dllPath = Path.Combine(Path.GetDirectoryName(pathXll), dllFileName);
if (File.Exists(dllPath))
return Assembly.LoadFrom(dllPath);
}
{
string dllPath = ExtractDllResource(dllFileNameWithoutExtension, dllFileName, 0);
if (File.Exists(dllPath))
return Assembly.LoadFrom(dllPath);
}

return null;
}
#endif

#if NETCOREAPP
[MethodImpl(MethodImplOptions.Synchronized)]
private static string ExtractDllResource(string resourceName, string dllName, int type)
{
byte[] dllBytes = GetResourceBytes(resourceName.ToUpperInvariant(), type);
if (dllBytes == null)
return null;

string dllPath = Path.Combine(tempDirPath, unmanagedDllName);
string dllPath = Path.Combine(tempDirPath, dllName);
if (!File.Exists(dllPath))
{
Directory.CreateDirectory(tempDirPath);
File.WriteAllBytes(dllPath, dllBytes);
}

byte[] pdbBytes = GetResourceBytes(unmanagedDllName.ToUpperInvariant(), 4);
byte[] pdbBytes = GetResourceBytes(resourceName.ToUpperInvariant(), 4);
if (pdbBytes != null)
{
string pdbPath = Path.ChangeExtension(dllPath, "pdb");
Expand All @@ -156,10 +187,8 @@ internal static string NativeLibraryResolve(string unmanagedDllName)
}

return dllPath;
#else
return null;
#endif
}
#endif

internal static Assembly LoadFromAssemblyPath(string assemblyPath)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
VisualStudioVersion = 18.3.11312.210 d18.3
VisualStudioVersion = 18.3.11312.210
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleDnaFileDefaultSuffix", "SingleDnaFileDefaultSuffix\SingleDnaFileDefaultSuffix.csproj", "{69CFC6E4-EAF6-416A-B462-B586DC3E051D}"
EndProject
Expand Down Expand Up @@ -144,6 +144,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOTPackNativeInclude", "AOT
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StartupHooks", "StartupHooks\StartupHooks.csproj", "{35B162DF-CC46-D126-0741-39D09EB547CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFControl", "WPFControl\WPFControl.csproj", "{90D59EA8-A127-5441-891E-610F278807BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDKWPF", "SDKWPF\SDKWPF.csproj", "{E34415DC-1220-D742-33A1-6F7BEB3A49CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -430,6 +434,14 @@ Global
{35B162DF-CC46-D126-0741-39D09EB547CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35B162DF-CC46-D126-0741-39D09EB547CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35B162DF-CC46-D126-0741-39D09EB547CE}.Release|Any CPU.Build.0 = Release|Any CPU
{90D59EA8-A127-5441-891E-610F278807BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90D59EA8-A127-5441-891E-610F278807BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90D59EA8-A127-5441-891E-610F278807BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90D59EA8-A127-5441-891E-610F278807BE}.Release|Any CPU.Build.0 = Release|Any CPU
{E34415DC-1220-D742-33A1-6F7BEB3A49CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E34415DC-1220-D742-33A1-6F7BEB3A49CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E34415DC-1220-D742-33A1-6F7BEB3A49CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E34415DC-1220-D742-33A1-6F7BEB3A49CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using ExcelDna.Integration;
using System;
using System.Windows;

namespace SDKWPF
{
public class Commands
{
[ExcelCommand(MenuText = "OpenWindow")]
public static void OpenWindow()
{
try
{
ShowWindow();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

private static void ShowWindow()
{
Window1 window1 = new Window1();
window1.ShowDialog();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;net8.0-windows</TargetFrameworks>
<UseWindowsForms>True</UseWindowsForms>
<UseWPF>True</UseWPF>

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup>
<ExcelAddInInclude>
WPFControl.dll;
ControlzEx.dll;
MahApps.Metro.dll;
Microsoft.Xaml.Behaviors.dll
</ExcelAddInInclude>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
<Reference Include="ExcelDna.Integration">
<HintPath>..\..\.exceldna.addin\tools\net6.0-windows7.0\ExcelDna.Integration.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<Reference Include="ExcelDna.Integration">
<HintPath>..\..\.exceldna.addin\tools\net462\ExcelDna.Integration.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WPFControl\WPFControl.csproj" />
</ItemGroup>

<Import Project="$(ProjectDir)..\..\.exceldna.addin\build\ExcelDna.AddIn.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Window x:Class="SDKWPF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SDKWPF"
xmlns:ext="clr-namespace:WPFControl;assembly=WPFControl"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Grid>
<ext:UserControl1 />
</Grid>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SDKWPF
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<UserControl x:Class="WPFControl.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WPFControl"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<mah:ColorPicker SelectedColor="{Binding myColor}"
mah:TextBoxHelper.ClearTextButton="True"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="Select a color"
/>
</Grid>
</UserControl>
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 System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFControl
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;net8.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MahApps.Metro" Version="2.4.11" />
</ItemGroup>

</Project>