Jump to content
  • Advertisement
Sign in to follow this  
killer_dead

polymorphism and dlls

This topic is 5050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

my question is simple : i've read in an old book that you cant use polymorphism from dll , but the book is too old. is it still the same? does calling functions from dll support polymorphism ? and if yes is there any difference between it and polymorphism in the same exe (.c++ file) ?

Share this post


Link to post
Share on other sites
Advertisement
I assume you meant 'calling polymorphic _class_ functions from DLL'. Well, I don't have much experience with DLL's but in my Game Programming Gems #2 there's a chapter about exporting clasess from DLL, which doesn't say anything that's NOT possible.
Also, it wouldn't make really sense, think about how many DLL's provide implementation of interfaces, in this case it's a must for polymorphism.
Concluding, AFAIK that book is wrong.

Quote:
and if yes is there any difference between it and polymorphism in the same exe (.c++ file) ?


There's only one type of polymorphism in C++ :-> and I don't think for DLL's it would be any different.

Share this post


Link to post
Share on other sites
Quote:
Original post by Koshmaar
There's only one type of polymorphism in C++


Actually, C++ supports more than one kind of polymorphism, in particular it supports both statically typed dynamically bound polymorphism (using virtual functions) and dynamically typed statically bound polymorphism (using templates).

- Neophyte

Share this post


Link to post
Share on other sites
IMHO templates don't count becouse they don't use _dynamic_ polymporphism, compared to virtual functions. In case you want to argue, OK, but then we should call macro definitons also polymorphic :-> which really doesn't make sense.

Share this post


Link to post
Share on other sites
If the DLL and the using EXE were compiled with the same compiler (or with compilers that use compatible vtable layouts) then polymorphism works between a DLL and an EXE (or another DLL).

Thus, you can declare a pure virtual interface in a header:


class MyPlugin {
public:
virtual void initialize( Parameters const & p ) = 0;
virtual void doStuff( int what ) = 0;
virtual void release() = 0;
};


Then, declare a factory function in your DLL:


class MyConcretePlugin : public MyPlugin {
public:
...
};
__declspec(dllexport) MyPlugin * MakePlugin()
{
return new MyConcretePlugin;
}


Then, in your EXE, you can walk through a folder (call it "plugins") using FindFirtFile("plugins\\*.dll"), and LoadLibrary() each of the files you find, and GetProcAddress() on the function MakePlugin. Then call it, to create an implementation of the MyPlugin interface from each of the DLLs you find.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!