Hello everybody,
I'm trying to create a (very) simple DLL by using D. Now I want export values
- is there any way do this... for example:
Example:
mydll.d:
export int i;
mydll2.d:
export int i = 99;
dll.d:
// Copied from http://www.digitalmars.com/d/2.0/dll.html
test.d:
import std.stdio;
import mydll;
void main() {
writefln(mydll.i);
}
-> The problem is (same problem for float, enum... , that I always get 0 by
calling mydll.i instead of 99.
I hope anyone can help me, please :)
Thanks for help in advance :)

I don't know much about dlls, but aren't you accessing mydll.i, which is
0, instead of mydll2.i, which is 99?

By using mydll2.i instead of mydll.i I didn't need a dll because the value (in
this case i) is defined in my compiled exe file (because mydll2.d will be
imported by compiling). So I can simply replace the dll but this has no effect
to my exe file (because i is defined in the exe)..... - I think :-D

Hello everybody,
I'm trying to create a (very) simple DLL by using D. Now I want export values
- is there any way do this...

Off the top of my head, I think it goes like this:
To export from a DLL:
export int i = 7;
To export from a DLL, with C name mangling:
export extern (C) int i = 7;
To import from a DLL:
export extern int i;
To import from a DLL with a C interface:
export extern extern (C) int i;
I'm not sure if I recall the export part correctly, it's been a while
since I actuall tried this.

Hello everybody,
I'm trying to create a (very) simple DLL by using D. Now I want export values
- is there any way do this...

Off the top of my head, I think it goes like this:
To export from a DLL:
export int i = 7;
To export from a DLL, with C name mangling:
export extern (C) int i = 7;
To import from a DLL:
export extern int i;
To import from a DLL with a C interface:
export extern extern (C) int i;
I'm not sure if I recall the export part correctly, it's been a while
since I actuall tried this.

It seems that export doesn't work for data, only functions. If you
build with -map, you'll see that i is not exported. I got it working by
using this .def file:
LIBRARY "mydll.dll"
EXETYPE NT
EXPORTS
D5mydll1ii
Then create the import lib with:
implib /s mydll.lib mydll.dll
/s adds the underscores.
If you use extern (C) the symbols will be a lot simpler to read and
write, though. Look at the .map file to see what the actual symbols are.

It seems that export doesn't work for data, only functions. If you
build with -map, you'll see that i is not exported. I got it working by
using this .def file:
LIBRARY "mydll.dll"
EXETYPE NT
EXPORTS
D5mydll1ii
Then create the import lib with:
implib /s mydll.lib mydll.dll
/s adds the underscores.
If you use extern (C) the symbols will be a lot simpler to read and
write, though. Look at the .map file to see what the actual symbols are.