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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dll interface

Status
Not open for further replies.

joeGrammar

Programmer
Jun 4, 2001
162
CA
If any of you find yourself creating a DLL in which you are going to create several console applications in which you wish to define a class, but don't wish to declare it several times, you may wish to do the following

1. declare the class within the dll
(this will save you from repeating code in each application)

2. Conditionally compile it so that it is ignored by the dll

( create a preprocessor variable which will disable the section of code, but here's the catch, you can't define the variable in the code, you'll have to put it in under preprocessor definitions in your project/settings/'C/C++' tab)

3. Include the file in your console application and define each member function as you would normally.

(You're able to do this because the preprocessor variable is not in the code, so this time, your code will not be ignored)

This will save you time and energy
 
could you give a short sample, step by step with smasll source samples? Maybe it'll be helpful for some members. John Fill
1c.bmp


ivfmd@mail.md
 
Sure!


#include <iostream.h>


#if defined(DLL_BUILD)
#define dllapi __declspec(dllexport)
#else
#define dllapi __declspec(dllimport)
#endif


class dllapi abstract

{

public:
abstract();
~abstract();


virtual void pvfun() = 0;
void dumbfun();

};

/*I wish to use the below class in several different console applications, because each console application uses pvfun() differently and I don't want to have to declare the class again, so in
our project options when building the dll, I will put as a precompiler variable &quot;DLL_BUILD&quot;*/


/*This line enables the compiler to ignore the code until later*/

#if !defined (DLL_BUILD)
class dllapi derived : public abstract

{

public:

derived();
~derived();

virtual void pvfun();


};
#endif

/*Now all we have to do is include this header file while compiling a console application. Since it will not have the precompiler description, it will recognize the code and we'll be able to specifically define it for each application*/
 
I think you don't need dllapi for declaration of derived, because in any dll implementaions it'll be ignored. So you do not need the declaration of derived in that .h at all. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top