Re: passing stl through dll
- From: Konran Udo Gerber <konran_u.gerber@xxxxxxxxxxxxxxx>
- Date: Sat, 23 Aug 2008 02:08:28 +0200
Hello,
I followed both articles referred in this thread and it seems to work with vector for me. But in case of string or basic_string<char> I run into deep trouble. The difference to things written in the articles is that I design a string class that is directly derived from std::string and does not have any other STL members (beside the traits and allocator that basic_string has itself. Here is some example code:
#ifdef STL_EXPORTS
# define STL_API _declspec(dllexport)
# define EXPIMP_STL
#else
# define STL_API _declspec(dllimport)
# define EXPIMP_STL extern
#endif
#include <string>
using namespace std;
typedef string STL_API CCHStrStd;
typedef struct char_traits<char> s_chTraits_t;
typedef class STL_API allocator<char> cl_chAlloc_t;
typedef class STL_API allocator<int> cl_iAlloc_t;
class STL_API CSTLStr : public string
{
// Konstruktion/Destruktion
public:
CSTLStr(void);
CSTLStr(const CSTLStr& rhs);
CSTLStr(LPCTSTR lpszStr);
virtual ~CSTLStr(void);
// Implementierung
public:
void Empty(void);
bool IsEmpty(void) const;
int GetLength(void) const;
char operator [](int iIndex) const;
char& operator [](int iIndex);
CSTLStr& operator =(const CSTLStr& rhs);
CSTLStr& operator +=(const CSTLStr& rhs);
CSTLStr& operator +=(char ch);
operator LPCTSTR() const;
friend CSTLStr STL_API operator +(const CSTLStr& l, const CSTLStr& r);
friend CSTLStr STL_API operator +(const CSTLStr& str1, LPCTSTR lstr);
friend CSTLStr STL_API operator +(LPCTSTR lstr, const CSTLStr& s2);
friend CSTLStr STL_API operator +(const CSTLStr& str, char ch);
friend CSTLStr STL_API operator +(char ch, const CSTLStr& str);
};
EXPIMP_STL template class STL_API allocator<char>;
/*EXPIMP_STL*//*explicit: */ extern template class STL_API basic_string<char, s_chTraits_t, cl_chAlloc_t>; // instantiation line with extreme trouble
////
For the last line I get error C2949 on EXPIMP_STL: explicit instantiation; auto and extern can't be used on same level of template specialization. I get this error when I either derive my CSTLStr from string or from basic_string<char> - so there obviously is already a template instance of it and I changed it to extern.
So the DLL file compiles fine ... but the client EXE file does not. In the EXE there is no use of STL (it is using MFC) and I get unresolved externals: two different d'tor messages for basic_string<char> (LNK2001, LNK2019). But there is no call to ~basic_string<char> in the EXE.
I'm also exporting two different derived vector classes and one derived hash_multimap class in the same DLL source made the same way as the string thing and I don't get errors for that.
Any hints on this? ...need really help as I don't understand this template stuff so -very- well.
Regards,
Konran
Alex Blekhman schrieb:
"S1" wrote:.It looks to me like the std::string might not be getting exported.
Yes, you need export everything that you use outside a DLL. Here's good article on the topic:
"VS.NET 2003 Warning C4251"
http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html
Alex
- Follow-Ups:
- Re: passing stl through dll
- From: Alex Blekhman
- Re: passing stl through dll
- References:
- Re: passing stl through dll
- From: S1
- Re: passing stl through dll
- From: Alex Blekhman
- Re: passing stl through dll
- Prev by Date: Re: passing stl through dll
- Next by Date: Re: passing stl through dll
- Previous by thread: Re: passing stl through dll
- Next by thread: Re: passing stl through dll
- Index(es):
Relevant Pages
|