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#
  4. How to call a C# Dll from C++ ??

How to call a C# Dll from C++ ??

Scheduled Pinned Locked Moved C#
csharpquestionc++databasesysadmin
4 Posts 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi, is there a possibility to call functions from a DLL written with C# from managed/unmanaged c++ code? I know it is very simple to create a C#DLL and then use the function in a C# Project with adding a reference. This is really great and simple. But... I have a very big project written with VC++6.0. I solved all problems after converting it to VC++7.0. But now I want to use the big, great new features like ADO.NET to connect to a SQL-Server. So I thought to write some C#DLLs with all the functions I need and then call these functions from C++. How can I do this? I tried several things. 1.) Is it possible to add a reference to a C#Dll from C++ ? I can't see a posibility... 2.) The old common way with LoadLibary is not possible, because I can't declare my function in the Dll as a dllexport function, and because of this GetProcAdress returns zero. :(( So how can I declare my function for external use ? Any ideas?? :confused: :confused: Thanks for help.

    J 1 Reply Last reply
    0
    • L Lost User

      Hi, is there a possibility to call functions from a DLL written with C# from managed/unmanaged c++ code? I know it is very simple to create a C#DLL and then use the function in a C# Project with adding a reference. This is really great and simple. But... I have a very big project written with VC++6.0. I solved all problems after converting it to VC++7.0. But now I want to use the big, great new features like ADO.NET to connect to a SQL-Server. So I thought to write some C#DLLs with all the functions I need and then call these functions from C++. How can I do this? I tried several things. 1.) Is it possible to add a reference to a C#Dll from C++ ? I can't see a posibility... 2.) The old common way with LoadLibary is not possible, because I can't declare my function in the Dll as a dllexport function, and because of this GetProcAdress returns zero. :(( So how can I declare my function for external use ? Any ideas?? :confused: :confused: Thanks for help.

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      The easiest thing to do would be to wrap your C# dll with COM (C# classes can be exposed as COM objects), then you can use COM to call into your C# dll... In MC++ you might be able to #using your dll like you would the system dlls. HTH, James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

      L 1 Reply Last reply
      0
      • J James T Johnson

        The easiest thing to do would be to wrap your C# dll with COM (C# classes can be exposed as COM objects), then you can use COM to call into your C# dll... In MC++ you might be able to #using your dll like you would the system dlls. HTH, James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

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

        The easiest way is to write an unmanaged C++ library that exports the functions you want. It then contains managed C++ that calls your C# classes directly. This gives you the best of both worlds, but requires two files. One for C++ and one cor C#.

        J 1 Reply Last reply
        0
        • L Lost User

          The easiest way is to write an unmanaged C++ library that exports the functions you want. It then contains managed C++ that calls your C# classes directly. This gives you the best of both worlds, but requires two files. One for C++ and one cor C#.

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          ohhh! I forgot about that :-O James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

          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