Shared static constructors from C# EXE

Benjamin Thaut via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 25 08:05:37 PST 2016


On Thursday, 25 February 2016 at 14:42:14 UTC, Thalamus wrote:
>> your entry point.
>
> Hi Guillaume,
>
> Thanks for responding so quickly! I had found that wiki page 
> before and I'd been following the "DLLs with a C Interface" 
> section closely. I had forgotten to add -shared when building 
> the DLL, but the behavior didn't change when I added it. So, I 
> added a call to Runtime.initialize() as the first line of the 
> endpoint I'm exposing. (I also made sure that this was the only 
> endpoint invoked and that it was only invoked once just to be 
> cautious.) I can see Runtime.initialize() being called, but the 
> Class A shared static constructor still is not called when run 
> from the C# EXE.
>
> Do you have any other ideas?
>
> In the meantime, I'm working on putting together a minimal 
> repro source, but the scenario is a bit complicated so there's 
> a lot of details to whittle away.
>
> thanks!
> Gene

You shouldn't be calling Runtime.initialize() manually. Just do 
the following in one of your source files:

import core.sys.windows.dll;
mixin SimpleDllMain;

This will generate a DllMain that will correctly initialize and 
deinitialize druntime.

Kind Regards
Benjamin Thaut


More information about the Digitalmars-d-learn mailing list