Creating DLL

Adam D Ruppe destructionator at gmail.com
Thu Jun 16 16:16:53 UTC 2022


On Thursday, 16 June 2022 at 16:07:41 UTC, Sergeant wrote:
> May I ask one more question: why a code like this would work in 
> D-application but not in D-DLL? (also I notice some other D 
> functions don't work in DLL):

Probably because the runtime not initialized properly. Export an 
Initialize() and Terminate() functions and call them from your 
application loading the dll.

Inside those functions:


export extern(C) void Initialize() {
    import core.runtime;
    Runtime.initialize();
}


export extern(C) void Terminate() {
    import core.runtime;
    Runtime.terminate();
}



If you call those the other functions should start working.

(this is a fairly common thing libraries need to do, but it might 
be tricky if you are loading the dll into an uncooperative 
application, there's other hacks for that, but having your 
functions like this and the app calling them are the right way to 
do it)


More information about the Digitalmars-d-learn mailing list