Add your comments page here.
I think there are some anachronisms in the DLL examples. For instance function pointers are called using (*fp)(args) syntax, but these days you can just call a function pointer like a normal function, fp(args).
Here's one way to make a DLL that you can call your D code from C/C++ (and probably any language that can grok the C ABI). First follow the procedure in the spec ( D 1.x, D 2.x) to create the DLL. Note that I found that this minimal .def file seems to suffice:
Namely it is not necessary to list your exports. They will still be in there if you have marked them as "extern(C) export" in the source files.
For convenience here is an example dmd DLL compile/link command:
You can also use Bud to create the dll. The only trick is that (with Bud v3.04) you need to add user32.lib and kernel32.lib.
Next you need to make a Microsoft COFF format import lib from the dll. Microsoft's lib.exe tool can do that, but it does need the list of exported functions in a .def file to work. Fortunately there's a free tool called 'pexports' that you can download that will do the trick:
Make sure Microsoft's VC bin directory is early on your path so that you get Microsoft's lib and not DMD's. Double check by typing 'lib' at the command prompt. If you don't see "Microsoft(R) Library Manager Version ..." then fix your path until you do.
For MinGW you can do:
Now you can use your favorite tools to link your C/C++ code to mydll_vc.lib.
This was tested with Visual Studio.NET 7.1 and 8.0, and with MinGW dlltool version 2.15.91.
NOTE: At the time of this writing (19-Feb-2007) Rebuild seem to have issues with building proper DLLs. Rebuild 0.8 just says "No 'link' setting configured."
- Corresponding page in the D Specification:
- Best Practicies guide for Dlls in D: BestPractices/DLL