Hello friends,

Suppose I want to write a dll file with MS-VC8.0 compiler. I need to add __declspec(dllexport) for all of the functions which will be called from outside of that dll.
Now my question is that whether it is possible to export all functions of that dll at a time, ie, without writing __declspec(dllexport) for all of the functions.

Thanx,
Amit

As far as I know, you have to put it before every function. I suppose you could save yourself a few keystrokes by doing this though.

#define DLLEXP __declspec( dllexport )

DLLEXP void someFunct() {
  // Code here
}

I think williamhemsworth's right, but I think you can export all members of a class in one swoop:

dll.h

#include <iostream>

#ifdef TWOMERS_BUILD_DLL
  #define TWOMERS_EXPORT __declspec(dllexport)
#else
  #define TWOMERS_EXPORT __declspec(dllimport)
#endif

class TWOMERS_EXPORT myClass {
  private:
    int thing;

  public:
    int returnThing();
    void setThing(int _thing);
};

dll.cpp:

#include "dll.h"

#define TWOMERS_BUILD_DLL

int myClass::returnThing() {
  return thing;
}
void myClass::setThing(int _thing) {
  thing = _thing;
}

Might be worth wrapping functions in a class if you want to save yourself some typing. Otherwise bite the bullet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.