Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is it possible to call C# dll methods in my Qt C++ project
Forum Updated to NodeBB v4.3 + New Features

Is it possible to call C# dll methods in my Qt C++ project

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 3.3k Views 2 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.
  • J Offline
    J Offline
    JohnTheNoob
    wrote on last edited by
    #1

    Hello everyone, Coming from .NET environment [VB & C#] with a beginner level in C++ and Qt and i was wondering is it possible to call methods from C# dll files in my Qt project.
    dll example:

    namespace Calc;
    
    public class Program{
          public int sum(int x,int y){
             return x+y;
          }
    }
    

    And i want to use the sum sum method in my Qt C++ project.

    1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #2

      Yes you can. The approach is to use the Qt side functions as a dll from c#.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      Pablo J. RoginaP 1 Reply Last reply
      1
      • J Offline
        J Offline
        JohnTheNoob
        wrote on last edited by
        #3

        @mrdebug Thank you for your answer, I was looking for topics on it and i found this one, is this the right approach ?
        https://programmersought.com/article/69592296458/

        1 Reply Last reply
        0
        • mrdebugM Offline
          mrdebugM Offline
          mrdebug
          wrote on last edited by
          #4

          As first step I suggest you to create a dll using QtCreator with the

          int sum(int a, int b)
          

          function.
          As second step, still with QtCreator I suggest you to create an application that uses the dll function above.
          As third step i suggest you to create a c# application that uses a standard dll. At this point you will already have right in mind how to use a dll so in c# you will find immediately the righth way.
          In the past i did it. Please have a look at these pieces of code:

          
                  [DllImport(@"Test01Wrapper.dll", CallingConvention = CallingConvention.Cdecl)]
                  private static extern void ProcessCommand(int Command, int Int0, int Int1);
          
          
                  private void BRelay_Click(object sender, EventArgs e) {
                      try {
                          ProcessCommand(0, 1, 2);
                      }
                      catch (DllNotFoundException error) {
                          OnLog(error.ToString());
                      }
                  }
          

          Need programmers to hire?
          www.labcsp.com
          www.denisgottardello.it
          GMT+1
          Skype: mrdebug

          1 Reply Last reply
          1
          • mrdebugM mrdebug

            Yes you can. The approach is to use the Qt side functions as a dll from c#.

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @mrdebug said in Is it possible to call C# dll methods in my Qt C++ project:

            The approach is to use the Qt side functions as a dll from c#.

            It looks like the OP is wanting quite the opposite... @JohnTheNoob said:

            call methods from C# dll files in my Qt project.

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            1
            • J Offline
              J Offline
              JohnTheNoob
              wrote on last edited by
              #6

              @mrdebug hi I'm really sorry for my late replay, sorry but I don't think i understand your answer right do you suggest me to create a C++ dll in Qt and use it in my project.
              What @Pablo-J-Rogina mention was right what i want to do is after i create my C# dll i want to use the methods in my C# dll inside my Qt project, (Use the methods in my C# dll inside my Qt C++ project) something like that.

              C# dll

              namespace Calc;
              
              public class Program{
                    public int sum(int x,int y){
                       return x+y;
                    }
              }
              

              and in my Qt project would be like this

              Program c;
              c.sum(2+3);
              
              JonBJ 1 Reply Last reply
              0
              • J JohnTheNoob

                @mrdebug hi I'm really sorry for my late replay, sorry but I don't think i understand your answer right do you suggest me to create a C++ dll in Qt and use it in my project.
                What @Pablo-J-Rogina mention was right what i want to do is after i create my C# dll i want to use the methods in my C# dll inside my Qt project, (Use the methods in my C# dll inside my Qt C++ project) something like that.

                C# dll

                namespace Calc;
                
                public class Program{
                      public int sum(int x,int y){
                         return x+y;
                      }
                }
                

                and in my Qt project would be like this

                Program c;
                c.sum(2+3);
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @JohnTheNoob
                Since you're not getting an answer here, and since this question is not to do with Qt per se but rather just with running C# from C++, do a Google search for that --- there will be plenty of hits.

                1 Reply Last reply
                1
                • J Offline
                  J Offline
                  JohnTheNoob
                  wrote on last edited by
                  #8

                  @JonB
                  "Since you're not getting an answer here" well i hope it will change and i will get an answer.

                  "and since this question is not to do with Qt per se but rather just with running C# from C++" I'm really sorry if this is the wrong place to ask such a question like this, i just thought that there will be a solution here.

                  "do a Google search for that --- there will be plenty of hits." yes I'm currently searching about it, but it's still good to ask on other places,increasing my chance of getting the answer I'm seeking

                  JonBJ 1 Reply Last reply
                  0
                  • J JohnTheNoob

                    @JonB
                    "Since you're not getting an answer here" well i hope it will change and i will get an answer.

                    "and since this question is not to do with Qt per se but rather just with running C# from C++" I'm really sorry if this is the wrong place to ask such a question like this, i just thought that there will be a solution here.

                    "do a Google search for that --- there will be plenty of hits." yes I'm currently searching about it, but it's still good to ask on other places,increasing my chance of getting the answer I'm seeking

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @JohnTheNoob
                    It's no problem to ask this here. However, there will be very few people who will be wanting to use C# in this forum, hence my suggestion for you may get a better answer elsewhere. I am/was a C# developer, but never had to call C# from C++, though I know it can be done.

                    Pablo J. RoginaP 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @JohnTheNoob
                      It's no problem to ask this here. However, there will be very few people who will be wanting to use C# in this forum, hence my suggestion for you may get a better answer elsewhere. I am/was a C# developer, but never had to call C# from C++, though I know it can be done.

                      Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by
                      #10

                      running C# from C++

                      A @JonB mentioned, your goal isn't related to Qt specifically, but rather it'd be a more C++ generic question.
                      I bet you'll find several examples on Internet about calling C# code from C++.
                      I'd suggest that you got some examples running without any Qt feature involved (i.e. plain C++ calling C# code) and once you're comfortable then move into using Qt widgets

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved