Elegant way to use dynamic bindings

Dennis dkorpel at gmail.com
Thu Mar 8 13:54:30 UTC 2018


On Friday, 9 February 2018 at 20:19:33 UTC, Dennis wrote:
> I'd still like to find a nice way to generate the boilerplate 
> code for dynamic loading, if I come up with something I'll post 
> it here.

So I ended up using an import library for a while, but I then 
wanted to get the handle of the DLL, which I don't know how to do 
with an import library. I also didn't like the non-customizable 
Windows pop-ups that appear when the libraries can't be found so 
I finally wrote some mixin code to generate the boilerplate for 
dynamic loading:

https://gist.github.com/dkorpel/3bf108ca48cb43bdbe3cc8bf30405b4d

Now you only need to declare the functions in a Struct:
```
struct FunctionsInMyDLL {
	int getVersion();
	string getName();
	// more functions
}
```
And the templates do the rest. :)


More information about the Digitalmars-d-learn mailing list