Thread: Sharing Classes using .DLL files?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    14

    Sharing Classes using .DLL files?

    MSVC++ 6.0, Win2k Pro

    Hi, perhaps someone knows how to solve this problem of mine..

    Im trying to share classes using .DLL files, Like for example, it's quite easy to share function, and I bet it's just as easy to share classes, however I haven't found out how yet.

    to share functions I simply use

    __declspec(dllexport) void func();

    and then to import it into another project

    __declspec(dllimport) void func();

    And of course, I Link it to.. I've understood that to export a class, I should use

    class __declspec MyClassName
    {
    public:
    int myint;
    }

    but how do I import it into my exe-project?

    Thx

    /Laos

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    to export the class(into DLL code):
    class __declspec(dllexport) MyClassName
    {
    public:
    int myint;
    }

    to import it (into another dll or EXE):

    class __declspec(dllimport) MyClassName
    {
    public:
    int myint;
    }

    the common way to archieve this is by using the preprocesor symbol as they do it in the MFC:
    #ifdef DLL_COMPLILING
    #define DLLCLASS __declspec(dllexport)
    #else
    #define DLLCLASS __declspec(importexport)
    #endif

    and use thet symbol in you class declaration:

    class DLLCLASS MyClassName
    {
    public:
    int myint;
    }

    when you complile your DLL, add a custom 'define' in your builing settings (Project/Settings/C++ tab/category = Preprocessor / Preprocessor definitions/)DLL_COMPILING

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    14

    Hmm?

    ok, so far I've understood to from reading the msdn docs, but what's good with this.

    The thing I want is to store a alot of classes inside a .DLL file and then use them without have to rewrite the class definition and all the member vars/funcs.

    like

    "export"

    class __declspec(dllexport) MyClass
    {
    int myInt;
    };

    "import"

    class __declspec(dllimport) MyClass;

    and now I want to be able to use the class as if it was defined in the same file.

    Is that possible, and if it is HOW???, that's what I wanted to know.

    thx

    /Laos

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  2. Class files including other classes
    By combatdave in forum C++ Programming
    Replies: 7
    Last Post: 11-04-2006, 12:37 AM
  3. Learning how to use classes and create header files
    By Welshy in forum C++ Programming
    Replies: 10
    Last Post: 04-19-2005, 12:33 PM
  4. Using .dll files
    By surendramalu in forum C Programming
    Replies: 1
    Last Post: 08-23-2004, 04:54 AM
  5. doin' classes in header files?
    By face_master in forum C++ Programming
    Replies: 9
    Last Post: 11-14-2001, 03:56 AM