Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ..
Posted
Updated 13-Aug-12 23:28pm
v2
Comments
Malli_S 14-Aug-12 6:07am    
Load the dll dynamically, rather using it statically.

From your description it looks like you are statically loading the DLL.

The solution would be to dynamically load the dll. Then you can check if the msi is installed and also whether the dll itself is present.

The disadvantage is that it can be tedious to update your code if you are using a lot of functions from this dll, since, you now need to change these functions to function pointers!

A compromise can be to use Delay loaded DLLs - see http://msdn.microsoft.com/en-us/library/151kt790.aspx

The dll would behave just like a statically loaded dll but would actually be loaded at the point when one of its functions are called by your application.

However, there are some limitations in using delay loaded dlls. For example, delay loaded dlls cannot import data.
 
Share this answer
 
Comments
vikuseth 14-Aug-12 7:12am    
i have followed your concept . project->properties->linker->advance->delay loaded dll ..
But after doing this i am getting a linker error regarding the respective lib file .
nv3 14-Aug-12 7:19am    
Probably the lib file is not in the right place. But delay loading your DLLs is your only option. If that doesn't help, you are forced to use LoadLibrary and GteProcAddress which is way more complicated and more work.
pasztorpisti 14-Aug-12 7:51am    
5ed, the problem is exactly what you described. To avoid problems with lot of exported functions the OP should export just one function from the DLL if its source is also available as I described in my answer here: http://www.codeproject.com/Answers/439261/When-to-write-Dynamic-Linking-Libraries#answer3
OP should check out the "Good advices if you write a DLL" section of the answer.
vikuseth 14-Aug-12 8:03am    
so in that delayed loaded dll section i have to choose "Support Unload (/DELAY:UNLOAD)" or "Don't Support Unload" ?
manoranjan 14-Aug-12 8:19am    
sorry, didn't understand your question fully. If you want to manually unload the dll, then you use /delay:unload and use __FUnloadDelayLoadedDLL2() to unload the dll. Otherwise, the dll will be unloaded when the application closes.
How about a starting helper ? :) :
C++
int main()
{
  HMODULE hLib(::LoadLibrary(_T("yourMainProcess.EXE")));
  if (!hLib) {
    ::MessageBox(NULL,
                 _T("Please install..."),
                 _T("Your pack"),
                 MB_OK | MB_ICONSTOP);
    return -1;
  }
  ::FreeLibrary(hLib);
  
  ::CreateProcess(/*Parameter list for yourMainProcess.EXE*/);
    
  return 0;
}
 
Share this answer
 
v6
Comments
nv3 14-Aug-12 6:04am    
As long as his .exe is linked with the DLL in question, this is not going to work as the application will not even load.
Eugen Podsypalnikov 14-Aug-12 6:13am    
Sorry, could not understand it from the first reading :) I will improve the solution...
Pablo Aliskevicius 14-Aug-12 6:41am    
Delay loading may do the trick.
vikuseth 14-Aug-12 7:14am    
i have used lots of dll .. so i dont think its feasible to go by your solution since i have to mention all my dlls name . Is there any other solution ?
Thankx for your reply ..
Eugen Podsypalnikov 14-Aug-12 9:28am    
I will try it, see above :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900