472,993 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 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 2267
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
5
by: Gianni Mariani | last post by:
The spirit of this arguably pointless exercise, is that the numeric_limits<T> class could be replaced with a totally generic template of compile-time, template computed constants. The problem is...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
2
by: Alfonso Morra | last post by:
I have a class declared as ff: class __declspec(dllexport) A { public: A() ; A(const A&) A& operator=(const A&) ; ~A() ; void doThis(void) ;
19
by: aaragon | last post by:
Hi everyone. A very simple question. I would like to know what is better in terms of performance. I want to use a simple function to obtain the minimum of two values. One way could be using a...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
9
by: Leo jay | last post by:
i'd like to implement a class template to convert binary numbers to decimal at compile time. and my test cases are: BOOST_STATIC_ASSERT((bin<1111,1111,1111,1111>::value == 65535));...
2
by: Gary Nastrasio | last post by:
I'm currently reading Andrei Alexandrescu's book "Modern C++ Design" and I'm a bit confused by one bit of template syntax in chapter 1. Here is a code example: template <class CreationPolicy>...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.