Unsolved Is it possible to call C# dll methods in my Qt C++ project
-
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.
-
Yes you can. The approach is to use the Qt side functions as a dll from c#.
-
@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/ -
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()); } }
-
@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.
-
@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);
-
@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. -
@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
-
@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. -
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