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. c++ dll in C#

c++ dll in C#

Scheduled Pinned Locked Moved C#
helpcsharpc++question
5 Posts 3 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.
  • K Offline
    K Offline
    kk tvm
    wrote on last edited by
    #1

    hi friends i have a c++ dll which contains function and class. c++ dll code

    class __declspec(dllexport) MyClass
    {
    public:
    MyClass(void);
    ~MyClass(void);
    void GetName()
    {
    .......
    }
    };

    _declspec(dllexport) void MyFun()
    {

    }

    My c# code follows

    public partial class Form1 : Form
    {
    [DllImport("CPPDLL.dll", EntryPoint="MyFun")]
    static extern void MyFun();

        \[DllImport("CPPDLL.dll", EntryPoint="MyClass")\]
        static class MyClass;
    
        public Form1()
        {
            InitializeComponent();
    
        }
    }
    

    but DllImport for class(MyClass) shows syntax error. how can i solve this problem thanks in advance

    -kk.tvm-

    P L 2 Replies Last reply
    0
    • K kk tvm

      hi friends i have a c++ dll which contains function and class. c++ dll code

      class __declspec(dllexport) MyClass
      {
      public:
      MyClass(void);
      ~MyClass(void);
      void GetName()
      {
      .......
      }
      };

      _declspec(dllexport) void MyFun()
      {

      }

      My c# code follows

      public partial class Form1 : Form
      {
      [DllImport("CPPDLL.dll", EntryPoint="MyFun")]
      static extern void MyFun();

          \[DllImport("CPPDLL.dll", EntryPoint="MyClass")\]
          static class MyClass;
      
          public Form1()
          {
              InitializeComponent();
      
          }
      }
      

      but DllImport for class(MyClass) shows syntax error. how can i solve this problem thanks in advance

      -kk.tvm-

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      DllImport doesn't work with classes. You can't import a class - if you need the class structure, it's up to you to redefine it as a struct at the C# side.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      K 1 Reply Last reply
      0
      • K kk tvm

        hi friends i have a c++ dll which contains function and class. c++ dll code

        class __declspec(dllexport) MyClass
        {
        public:
        MyClass(void);
        ~MyClass(void);
        void GetName()
        {
        .......
        }
        };

        _declspec(dllexport) void MyFun()
        {

        }

        My c# code follows

        public partial class Form1 : Form
        {
        [DllImport("CPPDLL.dll", EntryPoint="MyFun")]
        static extern void MyFun();

            \[DllImport("CPPDLL.dll", EntryPoint="MyClass")\]
            static class MyClass;
        
            public Form1()
            {
                InitializeComponent();
        
            }
        }
        

        but DllImport for class(MyClass) shows syntax error. how can i solve this problem thanks in advance

        -kk.tvm-

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

        Create a .NET library using C++.NET. Then use this library in C#.

        1 Reply Last reply
        0
        • P Pete OHanlon

          DllImport doesn't work with classes. You can't import a class - if you need the class structure, it's up to you to redefine it as a struct at the C# side.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          K Offline
          K Offline
          kk tvm
          wrote on last edited by
          #4

          Hi Pete O'Hanlon Redefine ?

          -kk.tvm-

          P 1 Reply Last reply
          0
          • K kk tvm

            Hi Pete O'Hanlon Redefine ?

            -kk.tvm-

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            It means you need to code up the C# equivalent.

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            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