1
我在VS 2010中编译和构建了一个DLL项目。我有一个添加到同一个解决方案的姊妹项目,它基本上链接到上面的DLL并需要加载它的构造函数和功能。但是,只要我尝试实例化对象,它就会给出access violation
。在DLL中没有实例化C++构造函数问题
在主,我这样做..
#include <iostream>
#include "MCaromDLL.h"
using namespace std;
using namespace MagneticCarom;
int main() {
. . .
MagneticCaromWrapper wrapper;
. . .
}
我 “MCaromDLL.h” 看起来是这样的:
// 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
注意,我想导出整个类(虽然我试着现在也出口个别funcs,但是徒劳无功)。整个代码可以根据要求提供。
不知道为什么的确切原因,但是当我尝试将对象更改为指针并包含'new'时,它开始调用构造函数而没有任何问题。有人能解释这里发生了什么吗? – Aditya369