I have compiled and built a DLL project in VS 2010. I have an added sister-project to the same solution which will essentially link to the above DLL and need to load its constructor and functionalities. However, as soon as I am trying to instantiate the object, it gives access violation.
In main, I do this..
#include <iostream>
#include "MCaromDLL.h"
using namespace std;
using namespace MagneticCarom;
int main() {
. . .
MagneticCaromWrapper wrapper;
. . .
}
My “MCaromDLL.h” looks like this:
// MCaromDLL.h
#define NULL 0
#define MAX_COLS 201 //Fixed based on the FEMM values
#define MAX_ROWS MAX_COLS //Fixed based on the FEMM values
#ifdef DLL_PROJECT
#define DLLSPEC __declspec(dllexport)
#else
#define DLLSPEC __declspec(dllimport)
#endif
#ifndef __MCAROMDLL_H__
#define __MCAROMDLL_H__
namespace MagneticCarom
{
. . . . . . .
class DLLSPEC MagneticCaromWrapper
{
private:
//All private members here...
public:
MagneticCaromWrapper();
MagneticCaromWrapper(int number);
virtual ~MagneticCaromWrapper();
//remaining functions
}
}
#endif
Note that I am trying to export the entire class (although I tried exporting individual funcs also, but in vain) now. The entire code can be made available on request.
Its always an issue to handle memory or structs over dll interface.
Things that can go wrong:
To make sure it works:
– Use a pure virtual interface
– Use a factory method
– Use a delete/release method
with an implementation.
At best do not throw exceptions cross dll boundaries.