.NET and C++ template

  • Thread starter Thread starter cipher
  • Start date Start date
C

cipher

I have created a C++ MFC dialog based appliction with .NET 2003. I am
trying to use a functioning MFC extension dll. There is a header file for
this dll that defines a template class. .NET errors when trying to compile
this file. This dll and it's associated headers compile and function just
fine under VC++ 6. Help is appreciated. Thanks


Here is the gist of the header file in question:

template<class TYPE>
class AFX_EXT_CLASS CGisPtrArray : public CArray<TYPE *,TYPE *>
{
public:
CGisPtrArray();
~CGisPtrArray();
...
};

template<class TYPE>
CGisPtrArray<TYPE>::CGisPtrArray()
{
}

....

Here's the error from .NET:
GisArray.h(22) : error C2491: 'CGisPtrArray<TYPE>::__ctor' : definition of
dllimport function not allowed

GisArray.h(28) : error C2491: 'CGisPtrArray<TYPE>::~CGisPtrArray' :
definition of dllimport function not allowed

This error is duplicated for every method of the template class.
 
cipher said:
I have created a C++ MFC dialog based appliction with .NET 2003. I am
trying to use a functioning MFC extension dll. There is a header
file for this dll that defines a template class. .NET errors when
trying to compile this file. This dll and it's associated headers
compile and function just fine under VC++ 6. Help is appreciated.
Thanks

It's not directly germane to your problem, but you can't use an MFC
extension DLL built with VC6 from a program built with VC7{.1}. You'll have
to recompile the DLL.

The particular problem you're encoutering seems to be one of preprocessor
#defines that are used to decorate exported/imported functions with
__declspec. This could be due to the VC6 -> VC7 incompatibilities in MFC
(I'm not an MFC user so I can't be sure).

-cd

PS: Follow-ups set to microsoft.public.dotnet.languages.vc - none of the
other groups are relevant.
 
I am also having the same problem, were you able to resolve it?

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Well, I got it working, I simply replaced the AFX_EXT_CLASS with declspec( dllexport ) and it compiled :-). Looks like the AFX_EXT_CLASS was getting translated to declspec( dllimport ) instead of declspec( dllexport ).

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Back
Top