Thread overview
Export values (enum, int, char[]...) for DLL
May 04, 2010
Nrgyzer
May 05, 2010
Ary Borenszweig
May 05, 2010
Nrgyzer
May 05, 2010
torhu
May 06, 2010
Nrgyzer
May 07, 2010
torhu
May 07, 2010
Nrgyzer
May 04, 2010
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 :)
May 05, 2010
Nrgyzer wrote:
> 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?
May 05, 2010
Ary Borenszweig Wrote:

> Nrgyzer wrote:
> > 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
May 05, 2010
On 04.05.2010 21:46, Nrgyzer wrote:
> 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.
May 06, 2010
torhu Wrote:

> On 04.05.2010 21:46, Nrgyzer wrote:
> > 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.

Thanks, but doesn't work :(

My files contain:

mydll.d:

module mydll;
export extern int i;

mydll2.d:

module mydll;
export int i = 7;

test.d:

import mydll;
import std.stdio;

void main() {
	writefln(i);
}

I can compile the dll, but when I compile test.d, I get the following error: "Error 42: Symbol Undefined _D5mydll1ii"
May 07, 2010
On 06.05.2010 16:06, Nrgyzer wrote:
> Thanks, but doesn't work :(
>
> My files contain:
>
> mydll.d:
>
> module mydll;
> export extern int i;
>
> mydll2.d:
>
> module mydll;
> export int i = 7;
>
> test.d:
>
> import mydll;
> import std.stdio;
>
> void main() {
> 	writefln(i);
> }
>
> I can compile the dll, but when I compile test.d, I get the following error: "Error 42: Symbol Undefined _D5mydll1ii"

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.
May 07, 2010
torhu Wrote:

> On 06.05.2010 16:06, Nrgyzer wrote:
> > Thanks, but doesn't work :(
> >
> > My files contain:
> >
> > mydll.d:
> >
> > module mydll;
> > export extern int i;
> >
> > mydll2.d:
> >
> > module mydll;
> > export int i = 7;
> >
> > test.d:
> >
> > import mydll;
> > import std.stdio;
> >
> > void main() {
> > 	writefln(i);
> > }
> >
> > I can compile the dll, but when I compile test.d, I get the following error: "Error 42: Symbol Undefined _D5mydll1ii"
> 
> 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.

Thanks - works :)