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. C / C++ / MFC
  4. How to Call C# DLL in VC++ win32?

How to Call C# DLL in VC++ win32?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpwpfc++tutorialquestion
5 Posts 5 Posters 0 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.
  • M Offline
    M Offline
    mathivanaan
    wrote on last edited by
    #1

    I am working in (Windows Presentation Foundation)WPF with C# environment. I have created simple DLL for C# with WPF. but how to call C# DLL from VC++ win32?. Following code of DLL:

    using System;
    using System.Collections.Generic;
    using System.Text;
    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 Test
    {
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class UserControl1 : UserControl
    {
    public UserControl1()
    {
    InitializeComponent();
    }

        private void button1\_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text = "Welcome to Tessolve";
        }
    }
    

    }

    Actually how to call C# dll function in Vc++ environment? Please share ur ideas or urls Regards, M.Mathivanan

    L C B R 4 Replies Last reply
    0
    • M mathivanaan

      I am working in (Windows Presentation Foundation)WPF with C# environment. I have created simple DLL for C# with WPF. but how to call C# DLL from VC++ win32?. Following code of DLL:

      using System;
      using System.Collections.Generic;
      using System.Text;
      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 Test
      {
      /// <summary>
      /// Interaction logic for UserControl1.xaml
      /// </summary>
      public partial class UserControl1 : UserControl
      {
      public UserControl1()
      {
      InitializeComponent();
      }

          private void button1\_Click(object sender, RoutedEventArgs e)
          {
              textBox1.Text = "Welcome to Tessolve";
          }
      }
      

      }

      Actually how to call C# dll function in Vc++ environment? Please share ur ideas or urls Regards, M.Mathivanan

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      There is an option to expose C# classes/methods to COM, so you would access them from C++ in that way. Take a look at some of the articles here on CodeProject: try a search for "C# COM".

      I must get a clever new signature for 2011.

      1 Reply Last reply
      0
      • M mathivanaan

        I am working in (Windows Presentation Foundation)WPF with C# environment. I have created simple DLL for C# with WPF. but how to call C# DLL from VC++ win32?. Following code of DLL:

        using System;
        using System.Collections.Generic;
        using System.Text;
        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 Test
        {
        /// <summary>
        /// Interaction logic for UserControl1.xaml
        /// </summary>
        public partial class UserControl1 : UserControl
        {
        public UserControl1()
        {
        InitializeComponent();
        }

            private void button1\_Click(object sender, RoutedEventArgs e)
            {
                textBox1.Text = "Welcome to Tessolve";
            }
        }
        

        }

        Actually how to call C# dll function in Vc++ environment? Please share ur ideas or urls Regards, M.Mathivanan

        C Offline
        C Offline
        Cool_Dev
        wrote on last edited by
        #3

        msdn page for what is told above http://msdn.microsoft.com/en-us/library/zsfww439%28vs.71%29.aspx[^]

        1 Reply Last reply
        0
        • M mathivanaan

          I am working in (Windows Presentation Foundation)WPF with C# environment. I have created simple DLL for C# with WPF. but how to call C# DLL from VC++ win32?. Following code of DLL:

          using System;
          using System.Collections.Generic;
          using System.Text;
          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 Test
          {
          /// <summary>
          /// Interaction logic for UserControl1.xaml
          /// </summary>
          public partial class UserControl1 : UserControl
          {
          public UserControl1()
          {
          InitializeComponent();
          }

              private void button1\_Click(object sender, RoutedEventArgs e)
              {
                  textBox1.Text = "Welcome to Tessolve";
              }
          }
          

          }

          Actually how to call C# dll function in Vc++ environment? Please share ur ideas or urls Regards, M.Mathivanan

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          There is another trick. mscorlib.dll itself is also a COM dll, i.e. you can instantiate a COM object with that. And then you can load your .NET dll via that object. I do not remember all the details, I guess following article could help you: Creating a host application for the .NET Common Language Runtime.[^]

          1 Reply Last reply
          0
          • M mathivanaan

            I am working in (Windows Presentation Foundation)WPF with C# environment. I have created simple DLL for C# with WPF. but how to call C# DLL from VC++ win32?. Following code of DLL:

            using System;
            using System.Collections.Generic;
            using System.Text;
            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 Test
            {
            /// <summary>
            /// Interaction logic for UserControl1.xaml
            /// </summary>
            public partial class UserControl1 : UserControl
            {
            public UserControl1()
            {
            InitializeComponent();
            }

                private void button1\_Click(object sender, RoutedEventArgs e)
                {
                    textBox1.Text = "Welcome to Tessolve";
                }
            }
            

            }

            Actually how to call C# dll function in Vc++ environment? Please share ur ideas or urls Regards, M.Mathivanan

            R Offline
            R Offline
            Rolf Kristensen
            wrote on last edited by
            #5

            One simple solution is to create a CLI/Interop DLL compiled with /clr, this DLL can export standard C function, which the C++ code can call. When implementing the standard C functions in the CLI/Interop DLL , then one is able to call standard .NET code, and it is possible for the CLI/Interop DLL to have references to other standard .NET assemblies. This example hosts a WinForms control in a MFC application, but one could just aswell host a WPF control: WinFormIntegration Sample: Demonstrates Hosting a WinForms User Control in an MFC Application [^]

            modified on Friday, February 25, 2011 10:47 AM

            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