Archived

This topic is now archived and is closed to further replies.

the darkening

DLL exports

Recommended Posts

the darkening    122
Hi, I want to access a class inside a DLL, but also use it within the DLL. So I have to use "__declspec(dllexport)", no? But VC++ says me (if I try that): error LNK2005 "class ..." already defined in "...". I can avoid this if I use "extern" in the .h file (in which the class is used). But then I can''t reach the class outside of the DLL. Question: How do I avoid LNK2005 but also can use the class in my application ("extern __declspec(dllexport)" doesn''t work!)? Darkening

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
instead try
  
__declspec(dllimport);


i''m not sure tho......

Share this post


Link to post
Share on other sites
Dactylos    122
you should specify __declspec(dllexport) on the class (in the header file) when building the dll, and specify __declspec(dllimport) in the header when using the dll. Easiest is to use a #define.

ex.
        
// SomeClass.h

// ......

#ifndef BUILDING_DLL
#define DLL_EXPORT __declspec(dllexport)

#else
#define DLL_EXPORT __declspec(dllimport)

#endif

class DLL_EXPORT SomeClass
{
// whatever....

};

And then define BUILDING_DLL only when you are building the DLL.

Edited by - Dactylos on June 27, 2001 5:57:23 PM

Share this post


Link to post
Share on other sites
the darkening    122
Actually it works, but now I get the compiler warning C4273 (something like "Inconsistent DLL binding..." (I don''t know the English text, because I have a German version)). What does THAT mean! VC++ does a dllEXport if I write dllIMport. If I write dllEXport, it gives me nothing but errors. That''s really amazing!

Darkening

Share this post


Link to post
Share on other sites