DLL in D based on Tango
Sean Kelly
sean at f4.ca
Mon Jul 9 13:17:00 PDT 2007
BLS wrote:
> Sean Kelly schrieb:
>> BLS wrote:
>>> Hello,
>>> My question is :
>>> Can I create a DLL written in *D* having a simple C Interface *A*
>>> scripting language can use ?
>>> Probabely yes.
>>> Using TANGO ? I do not know.
>>
>> Tango has two routines for initializing and terminating the runtime:
>>
>> extern (C) bool rt_init( void delegate( Exception ) dg = null );
>> extern (C) bool rt_term( void delegate( Exception ) dg = null );
>>
>> Call these in DllMain or wherever appropriate. The delegate will be
>> passed any exceptions thrown while the functions are processing, and
>> will return true/false on success/failure.
>>
>> As for the rest, building a DLL in Tango should be the same as doing
>> so with Phobos.
>>
>>
>> Sean
>
> Thank you Sean !
> Sean :
> > Tango has two routines for initializing and terminating the runtime:
> >
> > extern (C) bool rt_init( void delegate( Exception ) dg = null );
> > Call these in DllMain or wherever appropriate.
>
> leaves a lot of room for improvements, f.i.:
>
> BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
> {
> switch (ulReason)
> {
> case DLL_PROCESS_ATTACH:
> gc_init(); // initialize GC
> ............
> case DLL_PROCESS_DETACH:
> ............
> Pretty sure it will make you shake your head - But I have to ask: Shall
> I simply replace gc_init() with rt_init().
The D runtime includes a bunch of stuff, including the GC. When you run
a D app, the runtime is initialized before main() starts, and one of the
things that happens is gc_init() is called. Assuming you want
DLL_PROCESS_ATTACH to be equivalent to 'starting' your DLL, then just
replace gc_init() with rt_init(). rt_init() will call gc_init() as a
part of its processing.
> I am sorry about beeing so uninformed:ignorant but I never really
> understand the GC/Runtime Tango/Phobos problem.
No problem. It's kind of tricky if you haven't spent time with that
portion of the code. That's one reason I decided to talk about the
runtime at the D conference.
Sean
More information about the Digitalmars-d
mailing list