www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How do you export a Class into a DLL? Plz someone.

reply David L. Davis <SpottedTiger yahoo.com> writes:
I've been spenting a good number of hours reading this, trying that, and I've
finally gotten the small test program to complie and link, but gI et an "Error:
Access Violation" error when I run it.

This is the Test Class in WinDLL.d:

# export class Test
# {
#    public:
#    export this()
#    {
#       printf("Test.this()\n");
#    }
#    
#    export ~this()
#    {
#       printf("Test.~this()\n");
#    }
#    
#    export void hello()
#    {
#       printf("Test.hello()\n");
#    }
# } 

Here's the .DEF file I used:

# LIBRARY      WinDLL
# DESCRIPTION  'Windows example DLL written in D'
#
# EXETYPE      NT
# SUBSYSTEM    WINDOWS
# CODE         PRELOAD DISCARDABLE
# DATA         PRELOAD SINGLE
#
#EXPORTS       _Class_6WinDLL4Test  

The _Class_6WinDLL4Test I hand wrote in after dmd and the linker didn't place
this entry in the DLL...not sure if I'm suppose to do it this way. But all three
of methods in the Class all showed up, so the "export" next to them seem to work
just fine.

Then I compiled the WinDLL.dll with the following line:
dmd windll.d windll.def

After downloading ftp://ftp.digitalmars.com/bup.zip, and extracting implib.exe
into "dmd\bin" directory.

I then created the WinDLL.lib with the following line:
implib /system windll.lib windll.dll

Used the following loader.d code below:

# import std.loader;
# import std.stdio;
#
# import WinDLL; 
#
# int main ( char[][] args )
# {
#    char[] sLibName = r"C:\dmd\WinDLL.dll";
#    
#    auto ExeModule xmod = new ExeModule( r"C:\dmd\WinDLL.dll" );
#    
#    writefln("\"%s\" is loaded", r"C:\dmd\WinDLL.dll");
#    
#    Test oTest = new Test;
#
#    return 0;
#
# } // end main()

And a final compile loader.exe with the following line:
dmd loader.d windll.d windll.lib

I sure hope someone can tell me what I'm missing, since I've mainly created "C"
EXE and .DLL in the past, I've never had any Classes to export into DLL
before...now it would be great if I could learn how it is done, by a Class Pro!
;) 

Thxs for any help, or pointers in advance!

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
Jul 19 2004
parent "Carlos Santander B." <carlos8294 msn.com> writes:
"David L. Davis" <SpottedTiger yahoo.com> escribió en el mensaje
news:cdi63b$11t3$1 digitaldaemon.com
| I've been spenting a good number of hours reading this, trying that, and
I've
| finally gotten the small test program to complie and link, but gI et an
"Error:
| Access Violation" error when I run it.
| ...

I think the standard DLL format (or whatever it's called) doesn't allow
that.
I know that currently there's no way to do that with DMD.

-----------------------
Carlos Santander Bernal
Jul 21 2004