troubleshooting Question

Creating a dll from a class

Avatar of michaelu77
michaelu77 asked on
C++
4 Comments1 Solution268 ViewsLast Modified:
Hello,

I have a class and want to make it available fpr Visual Basic in a dll.
It is a mathematical class and the dll should create one instance of it. The dll-functions are controling the class. I have written the following code. But when I call the dll from VB the program shuts down.

This is the C++ dll-File:

#include <windows.h>
#include "stdafx.h"
#include "stdio.h"
#include "cStoppingpower.h"

// Instance of the Class cStopping
// not available from outside - is controlled by x_ functions
cStopping xx;

void _stdcall x_setEnv(int z1, double m1, int z2, double E_max, int unterteilungen);

BOOL WINAPI DllEntryPoint ( HINSTANCE hDLL, DWORD dwREASON, LPVOID Reserved )
{
     return TRUE;
}


void _stdcall x_setEnv(int z1, double m1, int z2, double E_max, int unterteilungen)
{
 xx.setEnv( z1,  m1,  z2,  E_max,  unterteilungen);
}

What am I doing wrong? I think the error lies in this line "cStopping xx;" - but why can`t I create an instance of a class in an dll?

Thx

Michael U.


PS: Here is the headerfile cStoppingpower.h
#ifndef H_STOPPING
#define H_STOPPING

#include <windows.h>
#include "cKonstanten.h"
#include <math.h>
#include <vector>

class cStopping
{
private:
     cKonstanten konst;
     std::vector<double> stoppingpower;
     double obergrenze, energystep;

     double amax1(double value1, double value2);
     double amin1(double value1, double value2);

     double rpstop(int z2, double energy);

     void rstop(int z1, double m1, int z2, double E_max, int unterteilungen);

public:
      cStopping();
     
      cStopping(int z1, double m1, int z2, double E_max, int unterteilungen);
     
     ~cStopping() {}

     void  setEnv(int z1, double m1, int z2, double E_max, int unterteilungen);

     double  getSP(double energy);

     void  multSP(double faktor);

     double  obergr() { return obergrenze; }
     
     double  SP(int index);
     
     double  EN(int index);
};

#endif
ASKER CERTIFIED SOLUTION
jayesh_j_patel

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros