Shared static constructors from C# EXE
Thalamus via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 25 06:42:14 PST 2016
On Thursday, 25 February 2016 at 14:07:21 UTC, Guillaume Piolat
wrote:
> On Thursday, 25 February 2016 at 14:01:30 UTC, Thalamus wrote:
>> I don't control the EXE itself and the code I write to
>> interface with it must be either C# or JavaScript, but this
>> repros with a test C# driver EXE as well. The interfacing C#
>> code can only be aware of the exposed D DLL functions defined
>> in .def and shouldn't be aware directly of Class A, B, or
>> ClassMapper, the factory specifically, etc..
>>
>
> Make sure your DLL must initialize the D runtime, which is
> where shared static constructors should get called.
>
> http://wiki.dlang.org/Win32_DLLs_in_D
>
> Alternatively you can call Runtime.initialize() yourself in
> 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
More information about the Digitalmars-d-learn
mailing list