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. Using a C++ library in C#

Using a C++ library in C#

Scheduled Pinned Locked Moved C#
csharpc++question
4 Posts 3 Posters 1 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.
  • E Offline
    E Offline
    eggie5
    wrote on last edited by
    #1

    I need access to the parallel port, but as far as I can tell it isn't possible. But, in c/c++ it's really easy... Now, I want my application to be in C#... so would I be able to make c or c++ library and be able to use it in my C# app? I already tried the NTPort library. But it costs money and it has alot of features I don't even use in it... I have no clue how they get it to work... So, is a C/C++ library (DLL) possible? Or, is it just possible to do it straight though C# in some werid way I haven't found??? /\ |_ E X E GG

    A L 2 Replies Last reply
    0
    • E eggie5

      I need access to the parallel port, but as far as I can tell it isn't possible. But, in c/c++ it's really easy... Now, I want my application to be in C#... so would I be able to make c or c++ library and be able to use it in my C# app? I already tried the NTPort library. But it costs money and it has alot of features I don't even use in it... I have no clue how they get it to work... So, is a C/C++ library (DLL) possible? Or, is it just possible to do it straight though C# in some werid way I haven't found??? /\ |_ E X E GG

      A Offline
      A Offline
      Alexander Kojevnikov
      wrote on last edited by
      #2

      Yes you can use C++ functions from C# as long as they are exported from your C++ DLL. The function prototype in C# will look like this:

      [DllImport("my.dll")]
      public static extern int MyFunction(string param1, int param2);

      You can check this MSDN arcticle for details: Consuming Unmanaged DLL Functions[^] Alexandre Kojevnikov MCAD charter member Leuven, Belgium

      E 1 Reply Last reply
      0
      • E eggie5

        I need access to the parallel port, but as far as I can tell it isn't possible. But, in c/c++ it's really easy... Now, I want my application to be in C#... so would I be able to make c or c++ library and be able to use it in my C# app? I already tried the NTPort library. But it costs money and it has alot of features I don't even use in it... I have no clue how they get it to work... So, is a C/C++ library (DLL) possible? Or, is it just possible to do it straight though C# in some werid way I haven't found??? /\ |_ E X E GG

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        Complie the C/C++ project with the /clr switch and place the main methods you intend using in a psuedo MC++ class. That class will be accessible in .NET. leppie::AllocCPArticle(Generic DFA State Machine for .NET);

        1 Reply Last reply
        0
        • A Alexander Kojevnikov

          Yes you can use C++ functions from C# as long as they are exported from your C++ DLL. The function prototype in C# will look like this:

          [DllImport("my.dll")]
          public static extern int MyFunction(string param1, int param2);

          You can check this MSDN arcticle for details: Consuming Unmanaged DLL Functions[^] Alexandre Kojevnikov MCAD charter member Leuven, Belgium

          E Offline
          E Offline
          eggie5
          wrote on last edited by
          #4

          Ok, thanks. I'll look into it. /\ |_ E X E GG

          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