F
flaviu_
Guest
I am trying to create a DLL where I put a code which can be modified in the future. And because the main application should updated time to time, I must load this DLL on runtime only ... the problem is that I am not sure how to do that. What I have tried: I have created a DLL (a MFC DLL), and here is the source code:
header:
#ifdef DECODER_EXPORTS
#define DECODER_API __declspec(dllexport)
#else
#define DECODER_API __declspec(dllimport)
#endif
// This class is exported from the Decoder.dll
class DECODER_API CDecoder {
public:
CDecoder(void);
// TODO: add your methods here.
virtual ~CDecoder();
BOOL DecodeInfo(const CString sInput, CStringArray& saData);
public:
CString m_sError;
};
extern DECODER_API int nDecoder;
DECODER_API int fnDecoder(void);
and the implementation code:
CDecoder::CDecoder()
{
//
}
CDecoder::~CDecoder()
{
//
}
BOOL CDecoder:ecodeInfo(const CString sInput, CStringArray& saData)
{
saData.Add(sInput.Left(3)); // just for testing purpose
return m_sError.IsEmpty();
}
and in my app I wrote:
#include "Decoder\Decoder.h"
#pragma comment(lib, "Decoder\\Debug\\Decoder.lib")
....
//in some method:
CStringArray saData;
CString sTemp(_T("abcd efgh"));
CDecoder dec;
BOOL bRet = dec.DecodeInfo(sTemp, saData);
TRACE("%d|%d\n", bRet, saData.GetSize());
but I get a warning:
warning C4251: 'CDecoder::m_sError': class 'ATL::CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<_CharType>>>' needs to have dll-interface to be used by clients of class 'CDecoder'
and a link error:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall CDecoder:ecodeInfo(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >,class CStringArray &)"
Can you point me into right direction to solve this task ?
Continue reading...
header:
#ifdef DECODER_EXPORTS
#define DECODER_API __declspec(dllexport)
#else
#define DECODER_API __declspec(dllimport)
#endif
// This class is exported from the Decoder.dll
class DECODER_API CDecoder {
public:
CDecoder(void);
// TODO: add your methods here.
virtual ~CDecoder();
BOOL DecodeInfo(const CString sInput, CStringArray& saData);
public:
CString m_sError;
};
extern DECODER_API int nDecoder;
DECODER_API int fnDecoder(void);
and the implementation code:
CDecoder::CDecoder()
{
//
}
CDecoder::~CDecoder()
{
//
}
BOOL CDecoder:ecodeInfo(const CString sInput, CStringArray& saData)
{
saData.Add(sInput.Left(3)); // just for testing purpose
return m_sError.IsEmpty();
}
and in my app I wrote:
#include "Decoder\Decoder.h"
#pragma comment(lib, "Decoder\\Debug\\Decoder.lib")
....
//in some method:
CStringArray saData;
CString sTemp(_T("abcd efgh"));
CDecoder dec;
BOOL bRet = dec.DecodeInfo(sTemp, saData);
TRACE("%d|%d\n", bRet, saData.GetSize());
but I get a warning:
warning C4251: 'CDecoder::m_sError': class 'ATL::CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<_CharType>>>' needs to have dll-interface to be used by clients of class 'CDecoder'
and a link error:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall CDecoder:ecodeInfo(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >,class CStringArray &)"
Can you point me into right direction to solve this task ?
Continue reading...