Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

static classes exported from dll

Status
Not open for further replies.

Nosferatu

Programmer
Jun 9, 2000
412
0
0
RO
Does anybody know the procedure for exporting static classes from a DLL? When trying to export such a class, I get the error:
Error C2201
'identifier' : must have external linkage in order to be exported/imported
The specified static identifier was exported.


Thanks. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Got it...
It's impossible. Static declared data is local to the DLL and cannot be accessed from outside its memory space.

I just have to think of something else. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
It is possible... depending how you are exporting your data (the weird, hard "list all functions" way or the sleek _declspec way)...

In your .cpp file, when you declare your static members (they're only defined in the .h file), put this in front of 'em:
Code:
_declspec(dllexport)

I usually make a macro for this, along these lines:
Code:
#ifdef DLL
#define DLLEXPORT _declspec(dllexport)
#else
#define DLLEXPORT _declspec(dllimport)
#endif

Then, in your headers, declare your classes like this:
Code:
class DLLEXPORT MyClass
{
...
  static int my_num;
};

In your .cpp file, do this:
Code:
static DLLEXPORT MyClass::my_num;

Voila!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top