Solved

Instantiating a generic class

Posted on 2000-03-03
1
227 Views
Last Modified: 2010-04-10
Very simple.  I have created a generic class in Visual C++ v6.0 and built it into a .DLL.  How do I now call this class from another executable?
0
Comment
Question by:Fantino
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 2581621
The usual way is to export the class from your DLL:

class.h:
#ifdef _DLL // define this when building the DLL
#define __DYNLINK __declspec( dllexport)
#else
#define __DYNLINK __declspec( dllimport)
#endif

class __DYNLINK CMyClass: public CWhatever
{
public:
  CMyClass();
  virtual ~CMyClass();

// ...
};

class __declspec(dllexport) CMyClass: public CWhatever
created a class that is exported from a DLL
whereas
class __declspec(dllimport) CMyClass: public CWhatever
created a class that is imported from a DLL

As you certainly don't want to use 2 different header files,
#ifdef _DLL // define this when building the DLL
#define __DYNLINK __declspec( dllexport)
#else
#define __DYNLINK __declspec( dllimport)
#endif

creates an export modifier '__DYNLINK' that expands to the correct expression depending on what your're building. You could use it e.g. this way:

dll.cpp
#define _DLL
#include "class.h"

so the class will be exported.

When building the application, simple use
app.cpp

#include "class.h"

LONG WINAPI WinMain( ...)
{
//...
}

Additionally, you'll have to add your DLL import library to your project when building the application.

Please ask if you need more information or some clarification!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question