Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Shipping multiple architecture

Shipping multiple architecture

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++wpfcomgraphics
6 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Super Lloyd
    wrote on last edited by
    #1

    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!

    B 2 Replies Last reply
    0
    • S Super Lloyd

      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!

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      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???

      1 Reply Last reply
      0
      • S Super Lloyd

        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!

        B Offline
        B Offline
        Brisingr Aerowing
        wrote on last edited by
        #3

        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)
        
        G S 2 Replies Last reply
        0
        • B Brisingr Aerowing

          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)
          
          G Offline
          G Offline
          Garth J Lancaster
          wrote on last edited by
          #4

          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) :-)

          B 1 Reply Last reply
          0
          • B Brisingr Aerowing

            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)
            
            S Offline
            S Offline
            Super Lloyd
            wrote on last edited by
            #5

            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 with GetType().Module.GetPEKind(out pek, out ifm);

            All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!

            1 Reply Last reply
            0
            • G Garth J Lancaster

              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) :-)

              B Offline
              B Offline
              Brisingr Aerowing
              wrote on last edited by
              #6

              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???

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups