What To Do When You’re In UseDll() Hell

InstallShield gives you many ways to provide additional functionality to an installation. Custom Actions are one way. Scripting is another way. While working on a recent client project, I found the need to use a Standard DLL, and it brought back familiar problems that I have had in the past. This arose from my use of UseDll(). Let’s talk about some common problems you can have with this InstallScript function.

In a Basic MSI project, the main way to provide additional functionality is through custom actions. Here are different custom action types that can be used with DLLs:

  • Standard DLL – custom action calls a standard Windows DLL and places the result in a property.
  • Managed Code – custom action calls a method in a managed code class library and places the result in a property.
  • InstallScript – custom action based on a script that can call a DLL through UseDLL and UnUseDLL.

In InstallScript and InstallScript MSI projects, you just make calls to DLLs or class libraries from your script.

In order to call a method/function in a DLL, you have to first load the DLL. You do that with a call to UseDLL(). Next, you call the method in the DLL. Finally, you unload the DLL from memory with a call to UnUseDLL().

Here is a screenshot of typical script that uses a DLL called Utility.dll.


Call a method in a DLL, Version 1

Call a method in a DLL, Version 1



The code is very straightforward. I want to call a method in a Standard DLL named utility.dll. I have added utility.dll to the Support Files view, so in the script, I first make a call to MsiGetProperty() (my version has Ws in front of the name) to get SUPPORTDIR. Then, I build the path to the DLL. Next, I load the DLL into memory. Next, I call the method in the DLL. Finally, I unload the DLL from memory.

Generally, if you have a problem, it will be in the call to UseDLL(). In other words, the call will fail, and the DLL won’t be loaded into memory.

There are two common reasons that UseDLL() will fail:

  1. The path you pass to UseDLL is incorrect. This could be because the path is not what you think. Or the path could be correct, but the DLL you are loading is not there.
  2. The DLL you are loading has a dependency which is not present on the target system.

Here’s a another version of the above script. This time, we are loading a dependency of our DLL, which is msvcr100.dll.


Call a method in a DLL, Version 2

Call a method in a DLL, Version 2



Notice the script builds the path to the DLLs. It then changes the current directory to be that directory (something the Help topic for UseDLL suggests). It then loads msvcr100.dll. Then it loads our DLL, utility.dll. It then calls the method and sets a property equal to the return code. Finally, it unloads utility.dll and msvcr100.dll from memory.

If you have problems loading your own DLLs into memory and using them, you will now know a couple of things you can look for.

 

Mystery Exception in InstallScript MSI in InstallShield 2012

Recently I was working on a client project that was an InstallScript MSI installation. I had walked through the source code and had many several successful debug sessions until one tripped me up. I went to the toolbar, clicked the Debug button, and received an exception. The dialog box that showed the exception had a link I could click. When I did that, it created an email to send to InstallShield outlining the exception.

Here is a screenshot of that exception:

Mystery Exception in InstallScript MSI in InstallShield 2012

Unusual Exception in InstallScript MSI Project



Unfortunately, this information did not give me a clue to what was happening.

No matter what I did, I couldn’t get rid of the exception. At one time, I thought my installation of InstallShield 2012 was corrupted, so I did a Repair installation. That didn’t help.

Next, I rebooted the machine and tried to debug again. That didn’t help either.

After several other failed attempts to resolve the problem, I decided to look in the registry. It was there that I found the problem.

Earlier, I had installed the client’s previous installation and then uninstalled it. I found that during the uninstall, it left a lot of trash on the computer and in the registry. By trash, I mean that the uninstall was not complete. A lot of stuff was left behind. After I cleaned up the trash, I was able to successfully debug my new project.

I am just passing this on in the hopes that it might help someone in the future.

 

What to Do When You Get Build Errors That Make No Sense

This has happened to me more times than I can count.

You build your installation and test some aspect of it. You then go back to the InstallShield IDE and make a small change, then build it again. When you do, you get all kinds of errors that make no sense. Here is a screenshot of what I am talking about:


What to do when you get build errors that make no sense in InstallShield

An example of build errors that make no sense





All I did was make a small change, then rebuilt, and I got all these errors. So what’s the solution?

The solution is to just build it again and the errors will generally go away.

I don’t know why this happens. Perhaps files are locked the first time you try to build. Then they aren’t locked when you build a second time, and it succeeds. Whatever the case, I’ve found just build again and the errors usually go away.

 

What Exactly is the Key File of a Component?

You probably know that each Component in an InstallShield installation should have one of its files marked as the Key File of the component. But, do you know why that is?

A Key File is used by the Windows Installer to detect the component’s presence on the target system and whether it needs to be updated.

In order to create advanced Component settings, you must specify a Key File.

 

More Info on InstallShield 2012 Upgrade Discounts

I received some questions regarding my last post on the discounts being offered for those who upgrade to InstallShield 2012 by December 31, 2011. The clearest way I can state it is to just show the email I received from Flexera.


Upgrade to InstallShield 2012 NOW & Save 20-40%!*
Offer ENDS December 31, 2011

The customer demand for upgrading to InstallShield 2012 has been unprecedented. Realizing that many more of our customers would still like the opportunity to upgrade — effective immediately we are re-opening the 20% off upgrade promotion when you upgrade from ANY older version of Express, Professional or Premier. This includes end-of-life versions.

We are also introducing a new offer available to all InstallShield Professional and Express customers – Save 40% when you upgrade your Express or Professional license to the Premier Edition. This offer is available to Professional and Express customers on ANY version – including end-of-life versions!


I hope this information helps clarify your questions.