471,348 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

.NET and C++ template

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.

Jul 21 '05 #1
3 2225
cipher wrote:
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.
Jul 21 '05 #2
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...
Jul 21 '05 #3
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...
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

31 posts views Thread by nikola | last post: by
5 posts views Thread by Gianni Mariani | last post: by
2 posts views Thread by Rudy Ray Moore | last post: by
2 posts views Thread by Alfonso Morra | last post: by
19 posts views Thread by aaragon | last post: by
3 posts views Thread by Hamilton Woods | last post: by
45 posts views Thread by charles.lobo | last post: by
2 posts views Thread by Gary Nastrasio | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.