Solved

Directories and Dlls...

Posted on 1999-01-29
10
140 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now