Easier, SimplerThis document is aimed at removing the fear of writing DLLs (Dynamic Link Libraries) for beginners. A lot of beginners think DLLs are really complex, but in actual fact they are pretty simple.
Hopefully this will provide a template you can use to develop your own. The actual code doesn't do very much.
I have also included an idea I found in the Secure32.DLL (NT security, SSPI validation). This has a routine that returns the addresses of all routines in the DLL. I think this is a "good" way of coding, especially if you have a DLL with many routines and you don't want to have to keep calling GetProcAddress. Again, it's just the idea, and some explanatory notes on how _I_ did it.
File names are rather long. I did it this way for explanatory purposes only. I would expect "real" code to use more sensible naming conventions...
I have not attempted to explain all the Delphi functions used - use the F1 help.
I am a beginner. If I made a mistake, please email me back and tell me. This pack started off as notes to me so I could remember the correct way to do all these methods.
Things to remember when writing DLLs
- If you use long strings, then you have to use BORLANDMM. This is mentioned in the blank DLL library template that Delphi makes for you.
- I think threads could be a problem
- Some 3rd party controls are not DLL safe - this could cause strange AV (access violation) errors
- Make sure you tell your user what calling convention to use - I use StdCall (but so far we can't get that to work from C++, so this might be wrong)
- I would suggest making your own copies of parameters sent to the DLL as I have done. My logic is that the DLL is a "black box", you give it some info, and it gives you some info back out. I would rather separate my DLL as much as possible from the calling program, hence this method.
- ... more DLL related articles
Final wordsI was teaching myself the very basics of DLL programming the other day, and part of that involved me writing up a tutorial for my friends. Everything I have learnt about Delphi has either been self-taught, or through some Internet help - I love the strength of our community so would like to contribute. What goes around comes around...
Basically, this is very informal document with source code. The DLL itself is pretty useless, but I have tried to explain the things that initially cared me about this topic. "DLL" is an intimidating word for a lot of us and I have tried to unmask this monster and show people that it really is easy.