Shipping multiple architecture
-
I am writing a managed WPF Application. It is compiled against 'AnyCPU' as is common with C#. I would like to add/develop a C++/CLI component to my app. However C++/CLI is bound to an architecture (x86/x64/arm). Is there a... relatively easy way for me to ship all 3 architecture and have the system load the right DLL at runtime?
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!
-
I am writing a managed WPF Application. It is compiled against 'AnyCPU' as is common with C#. I would like to add/develop a C++/CLI component to my app. However C++/CLI is bound to an architecture (x86/x64/arm). Is there a... relatively easy way for me to ship all 3 architecture and have the system load the right DLL at runtime?
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!
You can try using the AddDllDirectory[^] method as the start of your application and add a directory containing the library for the current architecture. Just read the notes lower on the page on how to add the path to the default paths.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
-
I am writing a managed WPF Application. It is compiled against 'AnyCPU' as is common with C#. I would like to add/develop a C++/CLI component to my app. However C++/CLI is bound to an architecture (x86/x64/arm). Is there a... relatively easy way for me to ship all 3 architecture and have the system load the right DLL at runtime?
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!
Here is a class that can help with the idea in my previous post:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;namespace GryphonSoft.Utility.Runtime.InteropServices
{
/// /// Helper class to manipulate the DLL Search Path.
///
public static class DllSearchPath
{#region Fields private static Dictionary \_dllPathCookieDict; private static SetDefaultDllDirectories\_Delegate \_SetDefaultDllDirectories; private static AddDllDirectory\_Delegate \_AddDllDirectory; private static RemoveDllDirectory\_Delegate \_RemoveDllDirectory; #endregion #region Constructor static DllSearchPath() { \_dllPathCookieDict = new Dictionary(StringComparer.OrdinalIgnoreCase); IntPtr kernel32 = LoadLibrary("Kernel32.dll"); \_SetDefaultDllDirectories = Marshal.GetDelegateForFunctionPointer(GetProcAddress(kernel32, "SetDefaultDllDirectories")); \_AddDllDirectory = Marshal.GetDelegateForFunctionPointer(GetProcAddress(kernel32, "AddDllDirectory")); \_RemoveDllDirectory = Marshal.GetDelegateForFunctionPointer(NativeMethods.GetProcAddress(kernel32, "RemoveDllDirectory")); \_SetDefaultDllDirectories(0x00001000); /\* 0x00001000 == LOAD\_LIBRARY\_SEARCH\_DEFAULT\_DIRS \*/ } #endregion #region Delegates private delegate bool SetDefaultDllDirectories\_Delegate(int DirectoryFlags); private delegate IntPtr AddDllDirectory\_Delegate(string NewDirectory); private delegate bool RemoveDllDirectory\_Delegate(IntPtr Cookie); #endregion #region P/Invoke \[DllImport("Kernel32.dll")\] internal static extern IntPtr LoadLibrary(string lpFileName); \[DllImport("Kernel32.dll")\] internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); #endregion #region Public API /// /// Adds a directory from the DLL Search Path. /// /// The directory to add. /// If an error occurred while adding the directory. public static void AddDllDirectory(string dir)
-
Here is a class that can help with the idea in my previous post:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;namespace GryphonSoft.Utility.Runtime.InteropServices
{
/// /// Helper class to manipulate the DLL Search Path.
///
public static class DllSearchPath
{#region Fields private static Dictionary \_dllPathCookieDict; private static SetDefaultDllDirectories\_Delegate \_SetDefaultDllDirectories; private static AddDllDirectory\_Delegate \_AddDllDirectory; private static RemoveDllDirectory\_Delegate \_RemoveDllDirectory; #endregion #region Constructor static DllSearchPath() { \_dllPathCookieDict = new Dictionary(StringComparer.OrdinalIgnoreCase); IntPtr kernel32 = LoadLibrary("Kernel32.dll"); \_SetDefaultDllDirectories = Marshal.GetDelegateForFunctionPointer(GetProcAddress(kernel32, "SetDefaultDllDirectories")); \_AddDllDirectory = Marshal.GetDelegateForFunctionPointer(GetProcAddress(kernel32, "AddDllDirectory")); \_RemoveDllDirectory = Marshal.GetDelegateForFunctionPointer(NativeMethods.GetProcAddress(kernel32, "RemoveDllDirectory")); \_SetDefaultDllDirectories(0x00001000); /\* 0x00001000 == LOAD\_LIBRARY\_SEARCH\_DEFAULT\_DIRS \*/ } #endregion #region Delegates private delegate bool SetDefaultDllDirectories\_Delegate(int DirectoryFlags); private delegate IntPtr AddDllDirectory\_Delegate(string NewDirectory); private delegate bool RemoveDllDirectory\_Delegate(IntPtr Cookie); #endregion #region P/Invoke \[DllImport("Kernel32.dll")\] internal static extern IntPtr LoadLibrary(string lpFileName); \[DllImport("Kernel32.dll")\] internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); #endregion #region Public API /// /// Adds a directory from the DLL Search Path. /// /// The directory to add. /// If an error occurred while adding the directory. public static void AddDllDirectory(string dir)
Nice Brisingr ! with not too much work you could publish it as an article here (I know Im bookmarking it or squirreling this code away) :-)
-
Here is a class that can help with the idea in my previous post:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;namespace GryphonSoft.Utility.Runtime.InteropServices
{
/// /// Helper class to manipulate the DLL Search Path.
///
public static class DllSearchPath
{#region Fields private static Dictionary \_dllPathCookieDict; private static SetDefaultDllDirectories\_Delegate \_SetDefaultDllDirectories; private static AddDllDirectory\_Delegate \_AddDllDirectory; private static RemoveDllDirectory\_Delegate \_RemoveDllDirectory; #endregion #region Constructor static DllSearchPath() { \_dllPathCookieDict = new Dictionary(StringComparer.OrdinalIgnoreCase); IntPtr kernel32 = LoadLibrary("Kernel32.dll"); \_SetDefaultDllDirectories = Marshal.GetDelegateForFunctionPointer(GetProcAddress(kernel32, "SetDefaultDllDirectories")); \_AddDllDirectory = Marshal.GetDelegateForFunctionPointer(GetProcAddress(kernel32, "AddDllDirectory")); \_RemoveDllDirectory = Marshal.GetDelegateForFunctionPointer(NativeMethods.GetProcAddress(kernel32, "RemoveDllDirectory")); \_SetDefaultDllDirectories(0x00001000); /\* 0x00001000 == LOAD\_LIBRARY\_SEARCH\_DEFAULT\_DIRS \*/ } #endregion #region Delegates private delegate bool SetDefaultDllDirectories\_Delegate(int DirectoryFlags); private delegate IntPtr AddDllDirectory\_Delegate(string NewDirectory); private delegate bool RemoveDllDirectory\_Delegate(IntPtr Cookie); #endregion #region P/Invoke \[DllImport("Kernel32.dll")\] internal static extern IntPtr LoadLibrary(string lpFileName); \[DllImport("Kernel32.dll")\] internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); #endregion #region Public API /// /// Adds a directory from the DLL Search Path. /// /// The directory to add. /// If an error occurred while adding the directory. public static void AddDllDirectory(string dir)
interesting.... though I thought of handling the
AppDomain.CurrentDomain.AssemblyResolve
event and load my assembly with a path of my choosing. Finding out whether the app is running as x86, x64, arm withGetType().Module.GetPEKind(out pek, out ifm);
All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!
-
Nice Brisingr ! with not too much work you could publish it as an article here (I know Im bookmarking it or squirreling this code away) :-)
I am planning on writing an article on the library when I get it closer to completion. That may be a while, though.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???