Class exporting in DLLS
I noticed VC++ 2003 defines exported classes like this:
class __declspec(dllimport) CPASM // or export, don''t wanna bunch it up with defines in this example
{
public:
CPASM(void);
~CPASM(void);
// TODO: add your methods here.
};
i''m used to doing it with an interface and defining a struct with virtual functions that inherits into a class and use a getinterface() function in the dll to create a new object for me... should i go back to this method or does VC++ 2003 make it easier to use function calls in run time load libraries?
Export the factory function only.
You dont have to export the class at all.
The factory creates a new instance of
implementor bur returns a pointer to the
interface the implementor implements.
eg.
// is it ok ?
[edited by - marius on January 25, 2004 1:04:48 PM]
[edited by - marius on January 25, 2004 1:06:11 PM]
[edited by - marius on January 25, 2004 1:10:28 PM]
You dont have to export the class at all.
The factory creates a new instance of
implementor bur returns a pointer to the
interface the implementor implements.
eg.
//common hdrstruct Abstract{ virtual void Foo()=0;}enum{I1,I2};//dllclass Implementor1 :Public Abstract{public: virtual void Foo(){cout<<"I'm Implementor1::Foo"}};class Implementor2 :Public Abstract{public: virtual void Foo(){cout<<"I'm Implementor2::Foo"}};declspec(__dllexport) Abstract* Factory(UINT what){ if (what==I1) return (Abstract*)(new Implementor1()); return (Abstract*)(new Implementor2());}//exe...dll stuffAbstract* pa1 = (P2_Factory)(I1);Abstract* pa2 = (P2_Factory)(I2);pa1->Foo();pa2->Foo();
// is it ok ?
[edited by - marius on January 25, 2004 1:04:48 PM]
[edited by - marius on January 25, 2004 1:06:11 PM]
[edited by - marius on January 25, 2004 1:10:28 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement