Re: Making plugin system with shared libraries. Upcast in shared lib
The idea is that the object you work with is responsible for casting itself to an interface you need.
Re: Making plugin system with shared libraries. Upcast in shared lib
It's how COM casts objects http://msdn.microsoft.com/en-us/library/ms687230.aspx
Re: Making plugin system with shared libraries. Upcast in shared lib
On Monday, 20 October 2014 at 15:07:43 UTC, MrSmith wrote: On Monday, 20 October 2014 at 14:05:29 UTC, Kagamin wrote: Do it the COM way: publish IModule2 interface and declare GetInterface method, which will return a prepared pointer, which you would reinterpret cast to IModule2. Will it work on linux with simple .so libs? I want it to be as simple as possible. Is it any different from what you already have? Dynamic cast is not guaranteed to work across dll boundary. If it does, you're lucky. If it doesn't, use GetInterface - that will work independently from runtime, environment, language, os, hardware etc.
Re: Making plugin system with shared libraries. Upcast in shared lib
On Tuesday, 21 October 2014 at 13:57:23 UTC, Kagamin wrote: On Monday, 20 October 2014 at 15:07:43 UTC, MrSmith wrote: On Monday, 20 October 2014 at 14:05:29 UTC, Kagamin wrote: Do it the COM way: publish IModule2 interface and declare GetInterface method, which will return a prepared pointer, which you would reinterpret cast to IModule2. Will it work on linux with simple .so libs? I want it to be as simple as possible. Is it any different from what you already have? Dynamic cast is not guaranteed to work across dll boundary. If it does, you're lucky. If it doesn't, use GetInterface - that will work independently from runtime, environment, language, os, hardware etc. What is GetInterface?
Re: Making plugin system with shared libraries. Upcast in shared lib
Do it the COM way: publish IModule2 interface and declare GetInterface method, which will return a prepared pointer, which you would reinterpret cast to IModule2.
Re: Making plugin system with shared libraries. Upcast in shared lib
On Monday, 20 October 2014 at 14:05:29 UTC, Kagamin wrote: Do it the COM way: publish IModule2 interface and declare GetInterface method, which will return a prepared pointer, which you would reinterpret cast to IModule2. Will it work on linux with simple .so libs? I want it to be as simple as possible.
Re: Making plugin system with shared libraries. Upcast in shared lib
On 10/20/2014 12:32 AM, MrSmith wrote: Than any module can search for registered modules and try to cast them to concrete type (upcast). That can't work because the notion of types only exists during compilation. Therefor it's not possible to load new types at runtime and use them in code that was compiled without knowing those types. You should simply use interfaces to achieve your goal.
Re: Making plugin system with shared libraries. Upcast in shared lib
On Monday, 20 October 2014 at 15:30:28 UTC, Martin Nowak wrote: On 10/20/2014 12:32 AM, MrSmith wrote: Than any module can search for registered modules and try to cast them to concrete type (upcast). That can't work because the notion of types only exists during compilation. Therefor it's not possible to load new types at runtime and use them in code that was compiled without knowing those types. You should simply use interfaces to achieve your goal. In this case ether shared lib knows actual type. But i've tried it with interfaces, (upcast also), or do you mean something else? 1) I want application to load IModule from .so/.dll 2) Any other module should be able to cast that IModule to actual type (upcast) and test if result is !null. 3) Can i do this using interfaces or without them? I.e. if in first example module2 is interface