www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to use dll

reply reimi gibbons <rei2x hotmail.com> writes:
Hi all,

I'm currently developing a software with D and Tango. I don't have much
knowledge on DLL, but i do know when linking to static lib you need a .h header
file, but do i need .h for linking with DLL as well?

also can anybody please provide a quick and small example to link with DLL.

*im trying to link my software with ICU lib, since mango seems outdated.

Thanks,
Reimi.
Jan 21 2009
next sibling parent Daniel Keep <daniel.keep.lists gmail.com> writes:
reimi gibbons wrote:
 Hi all,
 
 I'm currently developing a software with D and Tango. I don't have much
knowledge on DLL, but i do know when linking to static lib you need a .h header
file, but do i need .h for linking with DLL as well?
 
 also can anybody please provide a quick and small example to link with DLL.
 
 *im trying to link my software with ICU lib, since mango seems outdated.
 
 Thanks,
 Reimi.
You need two things to link to a DLL: 1. You need the interface of the DLL. In C/C++, this is provided by .h files; in D, this is simply provided by a D module. 2. Loader code. You can either roll your own, or generate the above two. You can use htod (it's somewhere on the official D pages) which tries to convert a C header file into a D import module. As for the loader code, you can either write a dynamic loader, or just use implib on the DLL to generate one (I think; it's been a while since I've had to roll one.) If I can remember more specific details, I'll post again, but that's the basic gist of it. -- Daniel
Jan 21 2009
prev sibling parent Sergey Gromov <snake.scaly gmail.com> writes:
Wed, 21 Jan 2009 23:19:48 -0500, reimi gibbons wrote:

 I'm currently developing a software with D and Tango. I don't have
 much knowledge on DLL, but i do know when linking to static lib you
 need a .h header file, but do i need .h for linking with DLL as well?
 
 
 also can anybody please provide a quick and small example to link
 with DLL. 
The easiest way is to link with an import library. It's exactly like linking with a static library. Actually you *are* linking with a static library, but that's a special kind of static library which forwards your calls to a DLL. This way runtime automatically loads the DLL before your program starts and unloads it after main() terminates, so you don't need to bother yourself with details. As Daniel pointed out, you can try to convert an existing .h file into a .d file using htod: http://www.digitalmars.com/d/2.0/htod.html The most reliable way to get an import library for your DLL is to get a .lib file in COFF format provided with the DLL and convert it into OMF format using coffimplib: ftp://ftp.digitalmars.com/coffimplib.zip
Jan 25 2009