How to export a variable from a DLL when compiling a D2 language with dmd?

What is the D2 __declspec (dllexport) language equivalent

I have a link D2 DLL sample code . Exporting functions in both the dmd namespace and the standard C namespace works like a charm. But I come across uncharted waters regarding the sharing of the global int variable between DLLs, as well as the main exe program ... I checked the DLL symbol table with depend22_x86, and while I tried to use the export directive just before the Var declaration, it does not appear in the DLL table , and the functions are performed. Is it possible to export Varibles to be visible in a DLL using the Digital Mars dmd toolchain?

+7
source share
3 answers

It was a bug in the compiler ( Bugzilla 10059 ). The following code should work now.

export __gshared int foo; 
+1
source

As a workaround, if exporting or importing global variables doesn't work, write a wrapper function of the form

 Type variable; extern(C) Type * getGlobalVariable() { return &variable; } 

if you want to export from D to C.

0
source

Maybe you can do what Ralph Tandecki says, but in the ctor static module. You do not have to explicitly call any function, all characters will be loaded. Maybe __gshared would be appreciated too.

0
source

All Articles