Thread: question about DLL's and class functions

  1. #1
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161

    question about DLL's and class functions

    hey.
    I'm tryin to find out a good way to do this, if it's possible:
    I've got some dlls that all consists of the same class. Like:
    Code:
    class ObjDll {
          void Draw(HDC hdc);
          ....//more functions
    }
    now, since there is gonna be many many of these DLL's with just
    some changes in them, I would like them to link to another "base"-dll so that the code and behaviour of these dll's would be easy to maintain. The thing is that I want this "base"-dll to act like the "default" functions. For exampel, the Draw(..) function draws the object calling a function Draw(..) that I want to be the same for several objects, but occasionally I want a dll to have it's own drawing routine. Err..this is kinda hard to explain..this might be something like what I want in semi-pseudo code:
    Code:
    class ObjDll {
         #ifdef IMPORTDRAW
         import function from base-dll
         #else
         void Draw();
    }
    so that if IMPORTDRAW is defined the class imports that function from the base-dll and otherwise just use void Draw() which would be defined in this specific dll's code.
    I can't seem to find a good way to do this..
    the only thing that comes to mind is to use plain (non-class) functions in the base dll and pass it all the necissary objects from the class but that would require a lot more work...and the idea isn't very appealing..
    anyone has any tips or pointers?
    thanks a bunch!
    /btq
    ...viewlexx - julie lexx

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Inheritance and polymorphism doesnt work for actual dlls (as you obviously know)

    The closest thing I can think of is implementing your dlls under com and using aggregation to manage which funcs are invoked from the interface given.

    It works like encapsulation.....1 com dll exists with its interface and another com dll uses that com object, and implements its interface by either passing calls onto the "base" object or reimplementing them.....

    You need to look at a decent com book for an implementation example as it's a lot of code and a lot of explaining

  3. #3
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    ouch..that sounds like a lot of work!
    well, I figured I might be best off just using function pointers.
    I started coding it and 2 serious problems occured.
    1: How to convert the FARPROC from GetProcAddress() into
    a member function.

    2: How to export the member functions.

    For #1 I found this code:
    Code:
    template<class Dest, class Src>
    Dest force_cast(Src src)
    {
    	union
    	{
    		Dest d;
    		Src s;
    	} convertor;
    
    	convertor.s = src;
    	return convertor.d;
    };
    at this site, and it seems ok.
    But for the exporting of these functions from the dll, or rather how to call them from GetProcAddress(..) I didn't find anything that wasn't "hacky".
    The problem is how to get the function..I've never used DLL's with classes before so I'm kinda helpless..
    How should I call it?
    like GetProcAddress(hIns, "MyClass::myFunc")
    or GetProcAddress(hIns, "myFunc")...? (none of these worked)
    I'm totally clueless but I was hoping that someone could help me out ?

    thanks a bunch!
    /btq
    ...viewlexx - julie lexx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question with accessing private data
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 01-18-2008, 03:14 AM
  2. Need someone familiar with DLLs
    By Kurisu33 in forum Windows Programming
    Replies: 9
    Last Post: 09-14-2006, 02:01 AM
  3. DLLs in C++
    By RoshanX in forum C++ Programming
    Replies: 0
    Last Post: 02-22-2006, 12:48 PM
  4. Help with Class Library .NET and Classes :0
    By Robert_Sitter in forum Windows Programming
    Replies: 2
    Last Post: 11-27-2005, 08:42 PM
  5. Evil dll's
    By master5001 in forum Windows Programming
    Replies: 4
    Last Post: 10-30-2002, 02:15 AM