Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 11, 2006 Beginner Question: Accesing a C .dll from D | ||||
---|---|---|---|---|
| ||||
Hi, I'm a C/C++ programmer. I'm very interested in D. At the moment my work requires the use of libsndfile (http://www.mega-nerd.com/libsndfile/). Am I right in thinking that I can access Windows .dlls from D? If so, is there an example of how to do this anywhere? Is this difficult to do? Cheers, Chris |
September 11, 2006 Re: Beginner Question: Accesing a C .dll from D | ||||
---|---|---|---|---|
| ||||
Posted in reply to cps | cps wrote: > Hi, > > I'm a C/C++ programmer. I'm very interested in D. > > At the moment my work requires the use of libsndfile > (http://www.mega-nerd.com/libsndfile/). Am I right in thinking that I can > access Windows .dlls from D? If so, is there an example of how to do this > anywhere? Is this difficult to do? > > Cheers, > > Chris You are correct that accessing Windows DLLs is possible in D. This page should be a great place to start learning more: Writing Win32 DLLs in D http://digitalmars.com/d/dll.html |
September 12, 2006 Re: Beginner Question: Accesing a C .dll from D | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | nobody wrote: > cps wrote: >> Hi, >> >> I'm a C/C++ programmer. I'm very interested in D. >> >> At the moment my work requires the use of libsndfile >> (http://www.mega-nerd.com/libsndfile/). Am I right in thinking that I can >> access Windows .dlls from D? If so, is there an example of how to do this >> anywhere? Is this difficult to do? >> >> Cheers, >> >> Chris > > You are correct that accessing Windows DLLs is possible in D. This page should be a great place to start learning more: > > Writing Win32 DLLs in D > http://digitalmars.com/d/dll.html That's about *writing* DLLs. Using them is much easier. All you need to do is (1) take the C header file (probably libsndfile.h), run htoD on it to make a D file (which will be called libsndfile.d). (2) take the C import lib, and if it's a Microsoft COFF format library (almost all are), run coffimplib on it. Say this creates a file libsndfile.lib. in libsndfile.d, add the line pragma(lib, "libsndfile.lib"); so that you don't need to specify it on the command line. Then your D program can just import libsndfile; Now go off and make some magic <g>. P.S. you can download htod and coffimplib from the DigitalMars site. Some links: http://www.prowiki.org/wiki4d/wiki.cgi?DigitalMarsTools |
September 12, 2006 Re: Beginner Question: Accesing a C .dll from D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | Don Clugston wrote:
> nobody wrote:
>> cps wrote:
>>> Hi,
>>>
>>> I'm a C/C++ programmer. I'm very interested in D.
>>>
>>> At the moment my work requires the use of libsndfile
>>> (http://www.mega-nerd.com/libsndfile/). Am I right in thinking that I can
>>> access Windows .dlls from D? If so, is there an example of how to do this
>>> anywhere? Is this difficult to do?
>>>
>>> Cheers,
>>>
>>> Chris
>>
>> You are correct that accessing Windows DLLs is possible in D. This page should be a great place to start learning more:
>>
>> Writing Win32 DLLs in D
>> http://digitalmars.com/d/dll.html
>
> That's about *writing* DLLs. Using them is much easier.
> All you need to do is
> (1) take the C header file (probably libsndfile.h), run htoD on it to make a D file (which will be called libsndfile.d).
> (2) take the C import lib, and if it's a Microsoft COFF format library (almost all are), run coffimplib on it. Say this creates a file libsndfile.lib.
>
> in libsndfile.d, add the line
> pragma(lib, "libsndfile.lib");
> so that you don't need to specify it on the command line.
>
> Then your D program can just
>
> import libsndfile;
>
> Now go off and make some magic <g>.
Just a quick note--for pragma(lib) to work, you must build the module containing the pragma into your program. Build does this automatically, but DMD/GDC do not :-)
Sean
|
Copyright © 1999-2021 by the D Language Foundation