D dll called from other lang app

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Jul 22 07:21:12 PDT 2007

"novice2" <sorry at noem.ail> wrote in message 
news:f7v5gi$2rrr$1 at digitalmars.com...
> Hello.
> Sorry for dumb question.
> I need to write dll (as plugin for app written on C). And i want to do it 
> with D instead of C.
> Is it possible?
> I can't imagine how garbage collect works, so i am afraid:
> can i use D dinamic arrays?
> can i use slicing?
> can i return D char[] to outside from dll?
> will GC work or i must care about memory myself?
> Are there any advises or general recomendations about this?
> (i already read http://www.prowiki.org/wiki4d/wiki.cgi?BestPractices/DLL, 
> and it explain me about type system only)
> If this already explained then give me link please.
> Thanx

Have a look at http://www.digitalmars.com/d/dll.html, especially the "DLLs 
with a C interface" section and the "Memory Allocation" section.

Probably the most important point on that list is " Retain a pointer to the 
data within the D DLL so the GC will not free it."  Basically you can return 
a char[] to the other language so long as (1) you keep a reference to that 
data inside your DLL before returning it, and (2) the other code does not 
try to free()/delete that data. 

More information about the Digitalmars-d-learn mailing list