Using .lib and .dll in D applications

moe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 20 04:25:04 PDT 2016


Thanks everyone for the info. It is very much appreciated!

What works for me right now is dealing with various packages (dub 
packages) and use them in projects. I previously made too many 
assumptions about how lib's and dll's work. It's much clearer now.

Where I still have a problem is with a plugin system. I would 
like to write an app that is plugin based. So that I can write a 
plugin to extend the functionality of the app. I imagine that I 
could copy the plugin into a folder from the (compiled) app and 
the app would be able to use the plugin without me having to 
recompile the app. I have been looking at LoadLibrary 
(https://dlang.org/library/core/runtime/runtime.load_library.html) and Object.factory (https://dlang.org/library/object/object.factory.html) but I don't quite get how to use them. I did find some info that was several years old. They mentioned that these functions are not yet ready for all platforms. I don't know if that has changed in the meantime. It is not clear from the documentation.

I would like to find some snippets or examples but that sort of 
resource for D is very hard to find online. Most of the time 
there are only some partial snippets where it turns out they only 
work under specific conditions or are restricted to one platform. 
Does D not supply some infrastructure for this kind of a task? It 
seams to me that is a very common approach to build an app. I 
expected there would be some out of the box solution for this in 
D. I would write the app and the plugins purely in D (no C 
bindings if possible).

I have tried to build a mini app which defines an interface for 
the plugins. The plugins then implement that interface. But when 
I want to load the plugin both LoadLibrary() and Object.factory() 
fail (I am aware that Object.factory() requires the full 
qualified class names).

Is there a recommended way of writing a simple plugin system that 
works on windows and linux? Maybe someone has a working example 
or knows a book that covers how to write a plugin system?


More information about the Digitalmars-d-learn mailing list