MrSmith via Digitalmars-d-learn
2014-10-19 22:32:14 UTC
I'm using Windows.
I was making some sort of modular system where you can define
modules that are loaded by host application.
Here is a simple example
https://gist.github.com/MrSmith33/7692328455a19e820a7c
Now i want to separate these "modules" in separate shared libs
and link them on the fly.
The issue i have is that some modules can define some useful
functions and in order to use them you need to upcast to concrete
type. This is easy in a single application, but i was unable to
do this through dll boundary.
So basically all dll's have factory function that returns an
instance of IModule.
Than any module can search for registered modules and try to cast
them to concrete type (upcast).
in imodule.d
interface IModule
{
string name();
void init(ModuleManager modman);
}
in module1.d (dll)
class Module1 : IModule
{
override string name() {return "Module1";}
override void init(ModuleManager modman)
{
IModule module2 = modman.findModule("Module2");
if (auto m = cast(Module2)module2)
{
m.someMethod2();
}
}
}
in module2.dll (dll)
class Module2 : IModule
{
override string name() {return "Module2";}
override void init(ModuleManager modman){}
void someMethod2(){}
}
And what files should i compile with what packages?
application
IModule
main
other
module1 dll
IModule
Module1
Module2 - should i import it, compile of import .di file?
module2 dll
IModule
Module2
Is it possible at all? Or it is an issue with Windows shared lib
support?
I was making some sort of modular system where you can define
modules that are loaded by host application.
Here is a simple example
https://gist.github.com/MrSmith33/7692328455a19e820a7c
Now i want to separate these "modules" in separate shared libs
and link them on the fly.
The issue i have is that some modules can define some useful
functions and in order to use them you need to upcast to concrete
type. This is easy in a single application, but i was unable to
do this through dll boundary.
So basically all dll's have factory function that returns an
instance of IModule.
Than any module can search for registered modules and try to cast
them to concrete type (upcast).
in imodule.d
interface IModule
{
string name();
void init(ModuleManager modman);
}
in module1.d (dll)
class Module1 : IModule
{
override string name() {return "Module1";}
override void init(ModuleManager modman)
{
IModule module2 = modman.findModule("Module2");
if (auto m = cast(Module2)module2)
{
m.someMethod2();
}
}
}
in module2.dll (dll)
class Module2 : IModule
{
override string name() {return "Module2";}
override void init(ModuleManager modman){}
void someMethod2(){}
}
And what files should i compile with what packages?
application
IModule
main
other
module1 dll
IModule
Module1
Module2 - should i import it, compile of import .di file?
module2 dll
IModule
Module2
Is it possible at all? Or it is an issue with Windows shared lib
support?