digitalmars.D.learn - Export values (enum, int, char[]...) for DLL
- Nrgyzer (18/18) May 04 2010 Hello everybody,
- Ary Borenszweig (3/30) May 05 2010 I don't know much about dlls, but aren't you accessing mydll.i, which is...
- Nrgyzer (2/33) May 05 2010 By using mydll2.i instead of mydll.i I didn't need a dll because the val...
- torhu (12/14) May 05 2010 Off the top of my head, I think it goes like this:
- Nrgyzer (16/39) May 06 2010 Thanks, but doesn't work :(
- Nrgyzer (27/75) May 13 2010 Hello,
- torhu (3/29) May 13 2010 Never tried exporting a class, but there's some info on this page:
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 04 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: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 :-DHello 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
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 05 2010
torhu Wrote:On 04.05.2010 21:46, 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"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
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 06 2010
torhu Wrote:On 06.05.2010 16:06, Nrgyzer wrote:Thanks - works :)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
Nrgyzer Wrote:torhu Wrote:Hello, dmd now exports all values successfully. But when I try to export a class, I get the following errors: "Error 42: Symbol Undefined _D5mydll1t7__ClassZ Error 42: Symbol Undefined _D5mydll1t5_ctorMFZC11mydll1t" Source of mydll.d is: export class t { export this(); } Source of mydll2.d is: import std.stdio: writefln; export class t { export this() { writefln("hello world!"); } } Source of test.d: pragma(lib, "mydll.lib"); import mydll; void main() { t myTest = new t(); } When I export D5mydll1t7__ClassZ in my def-File, I can compile it but when I try to create a new instance of t, I get an access violation :(.On 06.05.2010 16:06, Nrgyzer wrote:Thanks - works :)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 13 2010
On 13.05.2010 18:23, Nrgyzer wrote:Nrgyzer Wrote: dmd now exports all values successfully. But when I try to export a class, I get the following errors: "Error 42: Symbol Undefined _D5mydll1t7__ClassZ Error 42: Symbol Undefined _D5mydll1t5_ctorMFZC11mydll1t" Source of mydll.d is: export class t { export this(); } Source of mydll2.d is: import std.stdio: writefln; export class t { export this() { writefln("hello world!"); } } Source of test.d: pragma(lib, "mydll.lib"); import mydll; void main() { t myTest = new t(); } When I export D5mydll1t7__ClassZ in my def-File, I can compile it but when I try to create a new instance of t, I get an access violation :(.Never tried exporting a class, but there's some info on this page: http://prowiki.org/wiki4d/wiki.cgi?BestPractices/DLL
May 13 2010