Using a CString-derived class from a DLL file (LNK2019 &Q309801)

  • Thread starter Michael Buechel
  • Start date
M

Michael Buechel

Hi NG,

I've copied this from the article Q309801
(http://support.microsoft.com/default.aspx?scid=kb;en-us;309801).

---- schnipp ---------
You may receive an LNK2019 error message when you build a Visual C++ 2005 or
Visual C++ .NET application that uses a CString-derived class from a DLL
file
---- schnapp ---------

I've a similar problem by exporting a CArray derived class. In the article
the wrote the solution is to add

template class __declspec(dllimport) CStringT<TCHAR, StrTraitMFC<TCHAR,
ChTraitsCRT<TCHAR> > >;
template class __declspec(dllimport) CSimpleStringT<TCHAR>;

to your stdafx.h in your exe project.

I've tried to migrate the statement to my class by wrtiting:


// Forward declaration,
// @note The class CArgument is declared in the exe itself
class CArgument;

// TArray is my template derived from CArray
//
// template <typename _Ty, typename _A = const _Ty&>
// class AFX_EXT_CLASS TArray
// : public CArray<_Ty, _A>
// {
// :
// :

template class __declspec(dllimport) TArray<CArgument, const CArgument&>;
template class __declspec(dllimport) CArray<CArgument, const CArgument&>;

but i get also the LNK2019 error.

Does any one have an idea for this?
 
M

Michael Buechel

I found a solution:

do not use __declspec(dllexport) for the templates in the dll!

in my example this will done by AFX_EXT_CLASS.
remove the AFX_EXT_CLASS or __declspec(dllexport) and
it will work.

Note: You cannot export another class inheritated by the template
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top