• ### Popular Now

• 13
• 27
• 9
• 9
• 20

#### Archived

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

# DLL exports

This topic is 6107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
  __declspec(dllimport);

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

##### Share on other sites
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)#endifclass 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 on other sites
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