I have written a code in native C++ for a computationally expensive numerical analysis so program speed is a important factor. I would like to develop a GUI for a simple input instead of using a console version. I have very little experience with GUI development, but a Visual C++ Windows Forms seems easy enough with it is graphical interface. The problem is that writing the back-end of my code in managed CLR slows down the code by a factor of 3 which is of course a big factor. So i am wondering if it is possible to create a native dll from my unmanaged code and include it with the GUI developed with Windows Forms. Basically the calculations will be done by the native library will handle the computations and the front end is the Windows form created with managed code. This way the speed factor is not changed
I think I should be able to do that. However, i did not find much information on that on the net like the steps involved and the correct syntax (I am not too good with visual studio, i typically use GCC to compile my code).
The following is a sample C++ class that solves a quadratic equation, . I guess the obvious questions, does the dll have to be built a certain way, how do you include it in a project, how do you pass the parameters to the dll and call the functions…
#include <cmath>
using namespace std;
class QuadraticEquation // ax^2+bx+c=0
{
public:
QuadraticEquation();
void set(double A, double B, double C); //mutator function
void solve();
double get1stRoot(); //accessor function for first solution
double get2ndRoot(); //accessor function for second solution
private:
double a;
double b;
double c;
double x1; // first solution
double x2; // second solution
};
QuadraticEquation::QuadraticEquation()
{
a = 0, b = 0, c = 0, x1 = 0, x2 = 0;
}
void QuadraticEquation::set(double A, double B, double C)
{
a = A, b = B, c = C;
}
void QuadraticEquation::solve() // member function to solve the equation
{
double D = pow(b, 2.0) - 4 * a * c;
if(D>=0) // only then we get real solutions and not imginary ones
x1 = (-b + sqrt(D)) / (2*a), x1 = (-b - sqrt(D)) / (2*a);
}
double QuadraticEquation::get1stRoot()
{
return x1;
}
double QuadraticEquation::get2ndRoot()
{
return x2;
}
Thanks in advance
Last time i worked with windows Forms, i had a hell of a time using dll’s. You can include them with your project, and access them, but my experience doing so was not pleasant. That’s all i got
[edit]
i believe the answer to your question is yes, you can access a dll file of your own creation or whatnot. And from what i know, it doesnt have to be built a certain way.