D DLL crashes if not run on the main thread

raven09 dsaqwertyqh at jehg.com
Tue Sep 5 22:45:28 UTC 2023


Hi,
I've compiled a DLL using D and intended to use it with a C# 
winforms app using P/Invoke. Everything works wonderfully as long 
as it is called from the main thread (at least I assume that it 
not being on the main thread is causing the issues). If I start a 
new thread and try using any function imported from the DLL the 
program will instantly crash. Debugging the winforms app with VS 
shows that it does indeed crash on that function call, but does 
not provide any more information. Further testing I did was 
writing a test DLL that basically just contained `` extern(C) 
export int TestMe() { return 5; }`` and calling it in a new C# 
program: it worked fine until I put it in a separate thread.

I *assume* that this has something to do with D's GC? But I tried 
calling GC.disable() and nothing changed. Any help or insight 
would be appreciated.
Thanks in advance


More information about the Digitalmars-d-learn mailing list