C# using C++ dlls and lib

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    #1

    C# using C++ dlls and lib

    I have a program in C# that needs to access a couple of C++ dlls and libs.

    Can this be done?

    Thanks,

    Tom


  • Willy Denoyette [MVP]

    #2
    Re: C# using C++ dlls and lib


    "tshad" <tscheiderich@f tsolutions.comw rote in message
    news:O2HXVrJ9GH A.4476@TK2MSFTN GP04.phx.gbl...
    |I have a program in C# that needs to access a couple of C++ dlls and libs.
    |
    | Can this be done?
    |
    | Thanks,
    |
    | Tom
    |
    |

    You can only call functions exported by DLL's, C# (and all other .NET
    languages) cannot bind to libs.
    Note also that with "exports" I mean C style exported functions. Search the
    docs for PInvoke interop for more details.

    Willy.



    Comment

    • Arne Vajhøj

      #3
      Re: C# using C++ dlls and lib

      tshad wrote:
      I have a program in C# that needs to access a couple of C++ dlls and libs.
      >
      Can this be done?
      COM DLL's or Win32 DLL's.

      COM stuff can be used directly.

      Win32 DLL's can be used via dllimport.

      A very simple example:

      using System;
      using System.Runtime. InteropServices ;

      class MainClass
      {
      [DllImport("msvc rt.dll")]
      public static extern int system(string cmd);
      public static void Main(string[] args)
      {
      Console.WriteLi ne("Hello world");
      system("CLS");
      }
      }

      Arne

      Comment

      • Arne Vajhøj

        #4
        Re: C# using C++ dlls and lib

        Willy Denoyette [MVP] wrote:
        Note also that with "exports" I mean C style exported functions. Search the
        docs for PInvoke interop for more details.
        Good point.

        C++ mangled names is a problem.

        Arne

        Comment

        Working...