我有一個基類(QIndicator
),我想在DLL中實現派生類。在Visual Studio 2012 DLL項目用於樣本的派生類具有以下的代碼:與基類儘管正確的dllExport沒有功能導出到DLL - Visual Studio
頭文件
#ifndef _DLL_COMMON_INDICATOR_
#define _DLL_COMMON_INDICATOR_
// define the DLL storage specifier macro
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
class QIndicator
{
private:
int x;
int y;
};
extern "C"
{
// declare the factory function for exporting a pointer to QIndicator
DECLDIR QIndicator * __stdcall getIndicatorPtr(void);
}
#endif
源文件與派生類
#define DLL_EXPORT
#include "indicator.h"
class QIndicatorDer : public QIndicator
{
public:
QIndicatorDer (void) : QIndicator(){};
~QIndicatorDer (void){};
private:
// list of QIndicatorDer parameters
int x2;
int y2;
};
extern "C"
{
DECLDIR QIndicator * __stdcall getIndicatorPtr(void)
{
return new QIndicatorDer();
};
}
的我的問題是成功構建後,生成的DLL文件不包含導出的getIndicatorPtr
函數(如DependencyWalker所示)。我檢查了dllexport
關鍵字是否正確傳播到getIndicatorPtr
的聲明中。
另一個有趣的問題是,我已經在另一個DLL項目中有另一個派生類,就像我在幾個月前創建的那樣。這個較老的項目基本上是一樣的,一切都很好。我檢查了舊項目和當前項目的所有屬性,它們看起來完全相同。所以我用完了想法,爲什麼我不能得到getIndicatorPtr
導出。
任何幫助是非常讚賞, 丹尼爾
爲什麼在這裏使用'__stdcall'? – BitTickler 2015-04-06 13:10:35
「QIndicator」類未導出。您也需要導出課程。 – BitTickler 2015-04-06 13:12:23
在教程中發現它,誠實地(嘗試所有知道互聯網來解釋這個DLL行爲)..沒有它的工作。 – 2015-04-06 13:12:52