Exporting a class derived from exception? 
Author Message
 Exporting a class derived from exception?

Hi all.

I have a class that I'm exporting from my DLL using
__declspec(dllexport).  The class is derived from the class "exception",
and I'm getting a warning:

warning C4275: non dll-interface class 'exception' used a base for
dll-interface class 'MyClass'

What do I need to do about this?  I certainly don't want to modify the
EXCEPTION file in the VC includes.  Is this a benign warning such that I
can just disable the warning in my header file, or is this going to be a
problem?

My project has multiple DLLs, and the class that is derived from exception
will be used in another one of my DLLs.  (Imported using
__declspec(dllimport).)  Any help would be appreciated.

Gabe

(Btw, I'm using MSVC5 SP3.)



Sat, 23 Sep 2000 03:00:00 GMT  
 Exporting a class derived from exception?

Assuming your linking to the DLL version of the CRT and MFC then it should
be a benign warning.  MS didn't export the classes using the declspec
keyword, instead they used a DEF file (see the MFC\SRC directory on the CD).
Hence the base class doesn't decalre itself as exported.  But since your
using  the DLL version of MFC and the CRT then it is in fact exported an is
a non-issue.

If you statically link to the MFC and CRT then this is a problem

--
I wonder how much deeper would the ocean be without sponges.

 ------------------------------------------------------------
| Author for Pinnacle Publishing "Visual C++ Developer"     |
| http://www.pinpub.com/                                    |
| http://lucifer.lotus.com/jim/main.htm                     |
 ------------------------------------------------------------



Sat, 23 Sep 2000 03:00:00 GMT  
 Exporting a class derived from exception?



Quote:
>Hi all.

>I have a class that I'm exporting from my DLL using
>__declspec(dllexport).  The class is derived from the class "exception",
>and I'm getting a warning:

>warning C4275: non dll-interface class 'exception' used a base for
>dll-interface class 'MyClass'

>What do I need to do about this?  I certainly don't want to modify the
>EXCEPTION file in the VC includes.  Is this a benign warning such that I
>can just disable the warning in my header file, or is this going to be a
>problem?

>My project has multiple DLLs, and the class that is derived from exception
>will be used in another one of my DLLs.  (Imported using
>__declspec(dllimport).)  Any help would be appreciated.

>Gabe

>(Btw, I'm using MSVC5 SP3.)

I just looked at VC5's <exception>, and it appears to me that
std::exception is in fact exported. Are you linking to the static CRT?
If so, then you may want to link to the DLL version; the warning
should go away then, and if, for example, you have .exe A and .dlls B,
C, and D, usually it's best for all of them to link dynamically to the
same CRT.

To understand the warning, you have to think like a linker. Suppose
exception defines some non-inline functions that your derived class
calls. Where do those functions come from? If they're not imported,
they will come from a static library, so your DLL gets its own private
copies of those functions. Now, consider a client linking to your DLL.
As long as the exception functions were referenced only by code
belonging to your DLL, you should still be able to link, because the
DLL will use the functions statically linked into it. However, if your
DLL exposes an exception interface to your client, either directly or
indirectly by referencing it in an inline function, and the client
uses it, or if the client uses exception independently of the DLL, the
client has to link to the library containing the exception functions;
if the DLL linked statically to those functions, then the client will
be using different copies than the DLL, regardless of whether it links
statically or dynamically to them. Besides the obvious code bloat that
results from static linking, you may run into problems such as being
unable to free memory in the client that was allocated by the DLL, if
the CRT is being duplicated, since they will use different heaps.
Dynamically linking the client and DLL to the CRT avoids both these
problems.

--
Doug Harrison



Sun, 24 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Exporting class derived from std::exception hierarchy

2. Level 1 warning when deriving an exported class from an MFC class in VC++ 6.0

3. Exporting class from DLL when class derives from STL

4. Exporting a class derived from a template

5. Deriving from template classes and exporting from a DLL

6. New Class derived from Class which derived from CWindowImpl

7. Activating the class wizard on a derived-derived Cwnd class

8. How to Create CCtrlView derived class based on CTreeCtrl derived class

9. How to Create CCtrlView derived class based on CTreeCtrl derived class

10. W4 warning - throwing CObject derived class as exception

11. Addendum: COleServerDoc-derived class exception failure

12. COleServerDoc-derived class exception failure

 

 
Powered by phpBB® Forum Software