Solved

Instantiating a generic class

Posted on 2000-03-03
1
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

636 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