Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am racking my brain trying to come up with an elegant solution to a DLL load problem. I have an application that statically links to other lib files which load DLLs. I am not loading the DLLs directly. I did like to have some DLLs in another folder other than the folder that the executable is in. Something like %working_folder%\dlls - I did rather not have dozens (yes ... dozens) of DLLs in my %working_folder%.

I am trying to develop something that is part of the main app that will adjust the search path @ startup. The problem i am running into is that this new custom DLL path isnt in the system search path. When I start the app it crashes (STATUS_DLL_NOT_FOUND) because the necessary DLLs are not in the appropriate places. What I did like to do is to check @ startup if this new custom DLL folder is in the process environment variable search path and if not add it. Problem is, the application attempts to load all these DLLs before the app executes one line of code.

How do I fix this? I have considered writing a help app that starts first, adjusts the environment variables appropriately and the launches the main app via CreateProcess. This will work I am sure of it but it makes things difficult on the developers. When they debug the main app they are not going to launch a helper app first - not that they could even do that.

for more information please refer my unsolved prevous question
Dll implementation

:doh: :doh:
Posted
Comments
Olivier Levrey 1-Mar-11 5:27am    
I've answered your previous post. If my answer doesn't solve the problem, please comment on it!

santoshmaruti wrote:
I have considered writing a help app that starts first, adjusts the environment variables appropriately and the launches the main app via CreateProcess.

I think you may embed a similar mechanism inside the application itself, exploiting the Linker Support for Delay-Loaded DLLs[^].
Please note it's just an hypothesis, I haven't tested it.
:)
 
Share this answer
 
Comments
[no name] 1-Mar-11 6:48am    
Thanks,
its really work fine

you are one of the genius in world i think so
please keep in touch
i have lots of to come
CPallini 1-Mar-11 6:53am    
Nope, I'm just a guesser. Anyway I'm happy that it works and fit your needs.
[no name] 1-Mar-11 22:09pm    
but given link really help me to find my answer
I added a new answer to your previous post:
Separate folder for output DLLs from subprojects[^]
 
Share this answer
 
I just want to stop loading of dll before application start.
a link given by CPallini
help me to get this task. A Delay load option of linker input provide facility to stop dll loading before application start.
so now dlls are load when it called Loadlibrary(DLLNAME) function.

its now so easy to change applcation folder before dlls are load

so called of

SetCurrentDirectory(DLLFILE PATH) function change applcation path.

now dll called load from user define path.

like following coad:
if myApplication folder is C:\\DLLTRIAL\\

void CMainFrame::OnOk()
{
   SetCurrentDirecory("C:\\DLLTRIAL\\MYDLL\\"");
   HINSANCE TempHandle;
   TempHandle=AfxLoadLibrary("Test.dll");
   if(TempHandle!=NULL)
   {
      ShowDialog();         ////Dll function called
   }
   else
   { 
      AfxMessageBox("failed to load dll");
   }
}

to applied Dll loading dynamically

please click following link
DELAY LOAD


Thank all readers that review my question provide such good answers
:-D :-D :rolleyes: :rolleyes: :-\ :cool:
 
Share this answer
 
v2
Comments
Member 10066883 12-Sep-13 22:14pm    
I want to know the reasons why you use the function AfxLoadLibrary. Can i export a class from MFC Extension dll.

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