I am using one dll in my application for including the functionality provided by that dll . This dll i am getting after installing one msi . But in my application i have a requirement like if the user has not installed that msi then we have to show one warning message(e.g msi has not installed , code for this i have implemented in the main() of my application ) and have to exit from the application .

But the problem is if the user has not installed the msi , then while launching the application itself its showing one error message since its not able to get the dll and this time control not even coming to my main() where i have written the code for this msi checking (through registry entry).

Is there any efficient way to resolve this issue ..

I have the screenshot of the error message ..
Plz FDA .

Try exporting with /MT enabled.

Can you please explain what is /MT and how to enabled it ?

The solution to your problem is to use dynamic loading of the DLL. Look at the functions: LoadLibrary(), GetProcAddress(), and FreeLibrary(). This is basically the way that you can programmatically call a function (LoadLibrary) to load the DLL, then make calls to the GetProcAddress function to obtain function pointers to individual functions within the DLL, and then, once you are completely finished using the DLL, you can call FreeLibrary to un-load the DLL. This is, of course, a lot more trouble than doing it statically (the traditional way, where it gets loaded before you even start the main() function) because you have to manually assign all the function pointers via calls to GetProcAddress.

Another solution is to create a module of your own (a DLL) that has all the code that uses that DLL, but exposes fewer functions. Then, that new module would load the DLL in question statically (as usual), but be loaded dynamically by your main application. This way, you avoid having to dynamically load the external DLL, if that DLL has a lot of functions to be loaded from it, and you can still catch the error about the missing DLL.

N.B.: Under Unix/Linux/MacOSX systems, the equivalent functions to LoadLibrary / GetProcAddress / FreeLibrary are dlopen() / dlsym() / dlclose(), respectively.

Can you please explain what is /MT and how to enabled it ?

The /MT is a command-line option for the MSVC (microsoft visual C++) compiler that tells it to load the DLL under the same memory management (heap) as the main application. This is only valid if both the DLL and main application were compiled with the same compiler, same compiler version and same options. It has absolutely nothing to do with the question you asked. And in fact, it had no effect when doing dynamic loading as I suggested above.

It should tell you the specific DLL that it wants which in this case it didn't. In which you can just use local deployment and just include the DLL's in the same folder.

But this doesnt seem like a problem with missing DLL's. Dont quote me though.

Apart from mike_2000_17 suggestions, another alternative would be to use a launcher for your application.
launcher.exe which doesn't rely on the possibly missing dll, checks for the dll and if not found issues the error message and exits, otherwise it launches the main executable.

You could even embed the main executable as a resource of launcher, so if the dll is present and the main executable hasn't yet been written to disk, it just writes the resource exe to disk and then launches it.

I was going to suggest the same thing that mike_2000_17 did - build the system so it doesn't require the dll to get into main, and then dynamically load (link) it. This approach has worked well for me in the past, plus you can add functionality that way without rewriting/compiling/linking your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.