Solved

Directories and Dlls...

Posted on 1999-01-29
10
143 Views
Last Modified: 2010-04-06
I have an application which has A.EXE and B.DLL in C:\MyApp\ directory. In subdirectory C:\MyApp\Sub1\ I have C.DLL and D.DLL. When A.EXE is executed, it is loaded with B.DLL as well because A.EXE is statically linked with B.DLL.

When user click a button in A.EXE, A.EXE will dynamically call C.DLL in C:\MyApp\Sub1\. C.DLL will change the current directory to C:\MyApp\Sub2\, a new directory, using ChDir(), after that, C.DLL will dynamically call D.DLL. D.DLL is statically linked with B.DLL as well which is located in C:\MyApp\.

D.DLL cannot be loaded and gives me an error saying 'A required .DLL file, B.DLL, was not found.'.

A.EXE uses CreateProcess() to call C.DLL and B.DLL is already in the memory, why can't D.DLL be loaded? Any solution to this?

I've tried this, before C.DLL calls D.DLL, it changes the directory back to C:\MyApp\, then D.DLL can be loaded.

But what I don't understand is that, how do I make D.DLL understand that B.DLL has already in the memory?

Phew...a long one...
0
Comment
Question by:foxvision
  • 5
  • 3
  • 2
10 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1363780
First of all: Why do you use CreateProcess('d.dll') instead of LoadLibrary('d.dll')?

However, if you use something like this:
CreateProcess(extractFilePath(ParamStr(0))+'Sub1\c.dll');
or LoadLibrary(extractFilePath(ParamStr(0))+'Sub1\c.dll');
and the same for d.dll, everything should by fine.

Regards, Madshi.
0
 

Author Comment

by:foxvision
ID: 1363781
Sorry, Madshi.

I temporarily reject your answer as I've made a mistake. C.DLL is C.EXE and C.EXE is loading D.DLL using LoadLibrary.

Are the answer is still the same?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1363782
I think so. Please just try it and tell me if it works. But I'm quite sure about that...

Regards, Madshi.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:Wrath
ID: 1363783
Maybe im not understanding fully , but you can just put all your Dll's in the Windows/System directory, and access them from there...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1363784
I hate it when all programs put their dlls into the system directory. That makes sense only when a lot of applications are using the same dll, though in such a situation there are often version problems. And if the dlls are only used by one program, it doesn't make much sense to put them into the system directory. The user who looks in the system directory sees 10.000 dlls and does not know which dll belongs to which program. It's terrible. So IMHO it is much much better to put your private dlls in your private directory!

Regards, Madshi.
0
 

Author Comment

by:foxvision
ID: 1363785
Yes, Wrath, I agree what Madshi said. We have tried putting them in the SYSTEM directory in the first time and they work for us. The fact is, we don't want this, as this application is installed onto the server and we don't want only 1 or 2 files to be put into the workstations only to have a problem of updating thses files later.

Madshi, please give me a few days more to try out your solution. Thanks.
0
 

Expert Comment

by:Wrath
ID: 1363786
Well thats fine.. no problem,, The question was waiting on an answer and I answered the question, with an answer that worked, For some people using the systems directory is not a problem, I did not see anywhere in your question stating you did not want to use the system directory.. I apologize, im thought I was helping , dont take this as an attack, just stating my case for this situation :)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1363787
Hi Wrath, you don't need to apologize. Your suggestion works, though IMHO it's not the best one...    :-)

Regards, Madshi.
0
 

Author Comment

by:foxvision
ID: 1363788
Madshi, I didn't want the path to be hard coded, is it possible? If not possible, please repost your previous answer so that I can give you the point.
0
 
LVL 20

Accepted Solution

by:
Madshi earned 180 total points
ID: 1363789
I'm not sure what do you mean with hard coded?
Ok, the dlls have to be in hard coded directories but relative to your application's path.
So you could move your application from "c:\myApp" to "c:\programs\blabla" without any problems! Only the dlls have to be in the same RELATIVE subdirectory.
If you don't like that, you could search for the dlls and then give the found path into LoadLibrary. However, if the dlls neither are in the windows(\system) nor in your application's directory, you MUST tell windows the path. Otherwise windows won't find them...

Regards, Madshi.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 154
select query - oracle 16 100
Performance of SQL statement 37 127
how to resize animated Gif image in delphi ? 1 35
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question