2007-07-10

Quick tip for compiling/testing DLLs

Now that Delphi 2007 is using MSBuild, you can take advantage of the Pre-Build events to automate a common headache: killing that task that is using your DLL before you build it!

I'm currently developing an Outlook add-in so I found myself repeatedly quitting Outlook or getting an error because Delphi can't generate the DLL if I don't close Outlook, so, to solve that, and since, for some weird reason, I got used to always build instead of compiling, I just added the following command to this project's Pre-Build Events:

taskkill /F /IM outlook.exe

DIR >NUL

And that's all there is to it. You can also launch outlook after the build so as to immediately test your changes by adding the proper command to the Post-Build events, but I didn't add that as sometimes I do a few builds just to check syntax/compiler errors while I'm still working on something and I don't want to have outlook popup everytime...

Also, you can try without /F (force) and if your outlook or dll host can terminate gracefully in a speedy way you won't need to force termination, but in my PC and with Outlook it doesn't quit that fast, so I need the /F...

EDIT: The DIR >NUL command is just so that, should you not currently have outlook running, the error from taskkill won't stop your build process! :)

BTW: you can achieve something similar in BDS 2006 (and maybe 2005: haven't tested on this one), if you read my blog post about adding pre/post build events to BDS 2006...

5 comments:

HeartWare said...

Does the "Pre-Build" (and "Post-Build") events run only with Build, or also with Compile/Make?

Fernando Madruga said...

I can't swear by it but I believe it to be only Build related. A simple compile will not execute the pre/post build events.

Anonymous said...

dang, another function I never new was part of the os. very useful!

iSkomorokh said...

Will you show your Outlook add-in source code?

Fernando Madruga said...

iSkomorokh: I'm afraid this one is for a commercial project of mine, so the answer will be no! :)

But, as all my office add-ins, it's based around Add-In Express, so if you hop over to their site you can see some samples of code... :)