digitalmars.D - Runtime Dynamic Linking
- John C (69/69) Apr 15 2006 This is similar turf to the DDL project, but I couldn't see any examples...
This is similar turf to the DDL project, but I couldn't see any examples
for Windows DLL runtime linking. So I threw this together and while it
works and I do like it, I'm wondering if it can be improved upon.
It lets you define a way to call a function in a DLL without linking in
its import library.
So this -
wchar*, uint) MessageBox;
can be used as you would with a DLL import library, but it's linked at
runtime -
Now, here's the template code that does the magic.
void, T2 = void, T3 = void) {
entryPoint))(t0, t1, t2, t3);
entryPoint))(t0, t1, t2);
entryPoint))(t0, t1);
entryPoint))(t0);
entryPoint))();
void, T2 = void, T3 = void) {
There are some issues, obviously. FreeLibrary doesn't get called (fairly
straightforward to solve). And it should check if both the DLL and
function were found, throwing an exception if not.
My main question is this: can I get rid of the struct, maybe replacing
it with a delegate? I've been staring at it for so long I can't see the
alternatives.
Cheers.
Apr 15 2006








John C <johnch_atms hotmail.com>