How to create a DLL with C++.NET that can be used in VB.NET

Ok. I have this class written in C++.  I want to use it in a VB.NET project.  I need to know how to make this class into a DLL that can be used in VB.NET.  I have included the header file for my class.  I have read that the class must be "Managed" and being new to the .NET Enviroment, am having diffulty transforming my thinking to this new methodology.  I understand the basic concept behind it, but haven't quite grasped it totally, yet.  

If someone could help me get this into a DLL it would be quite helpful.  

Here is my header file:
-------------------------------------------------------------------------------------
//=========================================================== INCLUDES
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>

//========================================================= DEFINITIONS
#define pi       3.141593
#define twopi    ( 2.0*pi )
#define qrtrpi   ( pi/4.0 )
#define halfpi   ( pi/2.0 )

//===================================================== DEFINE NEW TYPES
struct pt {
      double z;
      double x;
};

struct surface {
      pt beg;
      pt end;
      pt cnt;
};

struct sCARLOS {
      surface s1;
      surface s2;
      surface s3;
      surface s4;
      surface s5;
      surface s6;
      surface s7;
      surface s8;
      surface s9;
      surface s10;

      // dynamic array
      pt *sting_res;
      int sting_pts;
};

struct sEMU {
      // dynamic arrays
      pt *s1;
      pt *s2;
      pt *s3;
      pt *s4;
      pt *s5;
      pt *s6;
      pt *s7;
      pt *s8;
      pt *s9;
      pt *s10;      

      // keep track of number of dynamic pts
      int s1_pts;
      int s2_pts;
      int s3_pts;
      int s4_pts;
      int s5_pts;
      int s6_pts;
      int s7_pts;
      int s8_pts;
      int s9_pts;
      int s10_pts;
};

//====================================================== CLASS DEFINITION
class ParametricWedge {
private:
      double WedgeAngle;            // degrees
      double WedgeLength;             // inches
      double Freq;                       // GHz
      double TailRadii;                // inches
      double BodyExt;                     // wavelengths
      int    Resolution;                 // pts per wavelength

      sEMU    EMU;
        sCARLOS CARLOS;

public:
      ParametricWedge();
      ParametricWedge(double Angle, double Length, double Freq, double Radii, double Body, int Res);
      ~ParametricWedge();
      void UpdateWedgeParams(double Angle, double Length, double Freq, double Radii, double Body, int Res);      
      void MakeWedge(double Angle, double Length, double Freq, double Radii, double Body, int Res);
      void MakeWedge();
      
public: //============================================== OVERLOADED MEMBERS
      double   GetWedgeAngle() { return WedgeAngle; }
      double   GetWedgeLength() { return WedgeLength; }
      double   GetFreq() { return Freq; }
      double   GetTailRadii() { return TailRadii; }
      double   GetBodyExt() { return BodyExt; }
      int      GetResolution() { return Resolution; }
      sEMU*    GetEMU() { return &EMU; }
      sCARLOS* GetCARLOS() { return &CARLOS; }

private:
      int OddNum(int val) { return val & 1; }      

};
--------------------------------------------------------------------------------------

Thanks for taking a look at it... Don
LVL 1
donfmorrisonAsked:
Who is Participating?
 
drichardsCommented:
Here's a converted header:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>

//========================================================= DEFINITIONS
#define pi       3.141593
#define twopi    ( 2.0*pi )
#define qrtrpi   ( pi/4.0 )
#define halfpi   ( pi/2.0 )

//===================================================== DEFINE NEW TYPES
namespace <namespace name here>
{
public __value struct pt {
     double z;
     double x;
};

public __value struct surface {
     pt beg;
     pt end;
     pt cnt;
};

public __gc struct sCARLOS {
     surface s1;
     surface s2;
     surface s3;
     surface s4;
     surface s5;
     surface s6;
     surface s7;
     surface s8;
     surface s9;
     surface s10;

     // dynamic array
     pt sting_res __gc[];
     int sting_pts;
};

public __gc struct sEMU {
     // dynamic arrays
     pt s1 __gc[];
     pt s2 __gc[];
     pt s3 __gc[];
     pt s4 __gc[];
     pt s5 __gc[];
     pt s6 __gc[];
     pt s7 __gc[];
     pt s8 __gc[];
     pt s9 __gc[];
     pt s10 __gc[];

     // keep track of number of dynamic pts
     int s1_pts;
     int s2_pts;
     int s3_pts;
     int s4_pts;
     int s5_pts;
     int s6_pts;
     int s7_pts;
     int s8_pts;
     int s9_pts;
     int s10_pts;
};

//====================================================== CLASS DEFINITION
public __gc class ParametricWedge {
private:
     double WedgeAngle;          // degrees
     double WedgeLength;            // inches
     double Freq;                    // GHz
     double TailRadii;              // inches
     double BodyExt;                  // wavelengths
     int    Resolution;               // pts per wavelength

     sEMU    *EMU;
     sCARLOS *CARLOS;

public:
     ParametricWedge();
     ParametricWedge(double Angle, double Length, double Freq, double Radii, double Body, int Res);
     ~ParametricWedge();
     void UpdateWedgeParams(double Angle, double Length, double Freq, double Radii, double Body, int Res);    
     void MakeWedge(double Angle, double Length, double Freq, double Radii, double Body, int Res);
     void MakeWedge();
     
public: //============================================== OVERLOADED MEMBERS
     double   GetWedgeAngle() { return WedgeAngle; }
     double   GetWedgeLength() { return WedgeLength; }
     double   GetFreq() { return Freq; }
     double   GetTailRadii() { return TailRadii; }
     double   GetBodyExt() { return BodyExt; }
     int      GetResolution() { return Resolution; }
     sEMU*    GetEMU() { return EMU; }
     sCARLOS* GetCARLOS() { return CARLOS; }

private:
     int OddNum(int val) { return val & 1; }    

};
}

You will, of course, need to implement the constructors, etc.  These types can then be referenced from VB.NET or C# projects.
0
 
drichardsCommented:
You need to use the managed extensions and create a managed C++ project.  Use '__gc class':

__gc class ParametricWedge {
...
};

You have to decide whether you want the structs to be value types or garbage-collected reference types (really classes in .NET).  Use either:

__gc struct pt {
...
};

to create reference types (need to use 'new' to create them) or

__value struct pt {
...
};

to create value types that are created on the stack.  Used in a managed C++ project, these types will be usable by another .NET language by adding a reference to the C++ project in the other .NET project.
0
 
drichardsCommented:
struct sCARLOS cannot be a __value struct because the internal pointer will be a __gc pointer.  That is not allowed in a __value type.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
drichardsCommented:
Same with sEMU
0
 
drichardsCommented:
Remember to create a managed C++ library - Class Library (.NET) in the project selections.
0
 
donfmorrisonAuthor Commented:
Wow.  Thank you very much.  I have not tried this yet, but I will out the project together later today, this project just got puched back a day in place of another.  Thanks so much!
0
 
drichardsCommented:
There is a bit of a difference between this and the original.  Note that the 'EMU' and 'CARLOS' members of 'ParametricWedge' are now pointers that need to be initialized in the constructors.  This is because these types needed to be reference types since they also contain pointers.
0
 
donfmorrisonAuthor Commented:
Yeah, I caught that.  I also posted another question about this project referring to some linking problems when I compile.  I am getting some unresolved external symbols. Here is a link to the question.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VisualC_PLUS_PLUS_DOT_NET/Q_21142418.html

Thanks again. I appreciate your help!
0
 
donfmorrisonAuthor Commented:
Another quick question about the modification you made...

Does the destructor need to specifically delete all the objects I create, or does the managed __gc stuff take care of that for me now?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.