?
Solved

design an application that runs without a DLL in the same directory?

Posted on 2003-02-27
11
Medium Priority
?
213 Views
Last Modified: 2008-02-01
i am having problem with having to run my application with a DLL. can anyone tell me how to run an application without it? thanx alot!!!!!!!!
0
Comment
Question by:HLLau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 8032446
Your question is very confusing....

If the application in question uses any of the exported functions from the DLL, then the DLL is REQUIRED and you must have it available.

If this is your application, then remove any dependencies on the DLL and rebuild it.  Then the DLL will not be needed.

If your problem is something else, I dunno, you've not provided enough details.

By the way, this is off topic here in the C++ topic area.
0
 
LVL 2

Expert Comment

by:corduroy9
ID: 8033627

From the title of your question, it seems you want to put the DLL somewhere else on your computer, besides in the folder where your program runs.

The DLL must be in the PATH or the local folder.  (go to an MS-DOS command prompt and type SET PATH to see what your path is.)

When your program runs, it looks first in your local folder for needed DLLs, then it looks in the PATH folders.  If needed DLLs are not found in any of these locations, then the program will fail.

A lot of people put DLLs in the c:\WINNT\system32\ folder.  This is ok, but you can lose track of your custom DLLs in there because there are so many other system DLLs in there.

If you're logged in as an admin, you can add a folder to the PATH environment setting (My Computer/Properties/Advanced) so that all your custom DLLs will be in one location.

Hope this helps...
0
 
LVL 12

Expert Comment

by:Salte
ID: 8033735
To run an application that uses a DLL which is not in the same directory any of the following methods can be used:

1. Place the DLL in question in some system directory where windows look for DLLs.

2. Place the DLL in question in some directory on the path or include the directory where the DLL is in your path.

3. IF you can load the DLL file explicitely yourself - as opposed to implicitely by windows at startup. You have far more options available. You can even select at run time which DLL to run and what to do if it wasn't found etc, where to find it and so on. This just tells you to find the DLL somewhere - wherever you want - and call LoadLibrary to load the DLL into your process memory space. When LoadLibrary is done you get a handle to the module and using that handle you can search for functions in that DLL:

int __stdcall (* some_func)(int x, const char * str);
HMODULE DLL_Handle = LoadLibrary("c:\\whatever\\dir\\SomeDLL.DLL");

some_func = (int __stdcall (*)(int,const char*))GetProcAddr(DLL_Handle,"SomeFunction");

Now you can call SomeFunction from that DLL.

int res = some_func(13,"some string");

In this last method you have full control for everything.

Alf
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Grass_Hopper
ID: 8051258
I agree with jhance, you need to give more details.

Name of dll, Framework/compiler etc.
0
 

Author Comment

by:HLLau
ID: 8056235
ok, i better repeat the ques.

i see that lots of programs run without DLL(or not without it, but it's invisible to the user)

i am using Borlad C++, when i'm writing a 32-bit program,
it must run together with a DLL(name: cw3230.dll)<-- this must be in the same directory with program.

what i want is to know how to write program without having to put it in the same dir or to include it in the main program. invisible to users
0
 
LVL 32

Expert Comment

by:jhance
ID: 8056388
CS3230.DLL is Borland C++'s C++ RUN TIME LIBRARY.

Either us IT or WRITE YOUR OWN RTL!
0
 
LVL 12

Expert Comment

by:Salte
ID: 8056428
HLLau,

I am not sure what that cw3230.dll does but your best bet is probably to arrange it so that that dll is stored in some directory and your program access it from that directory.

The most clean way to do that is to put the dll in the same directory as the .exe. The reason for this is that it is easiest for the user, if he wants to remove the program he just delete the directory and gone is both the program and the DLL. Placing the DLL in another directory means that the user must search for this DLL and then he finds it and he possibly do not know it is together with your program and he might end up deleting it without deleting your program etc etc. Then when you run your program it won't find the DLL and chaos arise.

So, the program require the DLL to be in the same dir as the exe. This is the best way to solve the problem. Why would want to do it differently?

If you don't want the user to have the DLL in his local directory, don't install the program in that local directory, install it in some other directory and place the DLL in that same directory.

As I wrote before you can use LoadLibrary("cw3230.dll") and that function can be given full path to the DLL so it can be placed anywhere, you can also handle that the file wasn't found at that place and for example try LoadLibrary() with a different path to search for the file in several places and also be able to terminate gracefully if the DLL couldn't be found. So you CAN have full control if you want.

On the other hand, why would you? Why is it so bad that the DLL have to be in the same dir as the EXE?

Placing the DLL in any other directory runs the risk that the user may some day see this DLL residing all by itself in a directory and not recognizing that the DLL is needed by your application he deletes it. Then when your application starts up you complain that you can't find the DLL and the user may have forgot that he deleted that DLL or it is a different user who at one time deleted it and the poor user who wants to run your program is stuck.

Why make things so difficult for your users? Why can't you just make things easy for them? PLace a DLL where it belongs: If the DLL is used by one application, place it together with that application. If the DLL is used by several applications place it in some common place and give the directory name something like "FooAppShared" so that the user knows that this is a DLL which is shared among all the Foo applications and won't delete it unless he has deleted all those applications.

Alf
0
 
LVL 12

Expert Comment

by:Salte
ID: 8056571
jhance,

HMmm.....

so he wants to get rid of the run time library?

well.....then he really is in for a hard time.

HLLau,

What do you have against the library?

You could define to load the static library (.lib) instead. It is possible that you cannot do that because you don't have the big enough version of the compiler to do it. Both Borland and Microsoft operate with several versions of their compiler platforms - a "student" version which has several limitations and one of them - I think - is that you cannot use a statically linked C library. In this case you have to buy a bigger compiler if you want to get rid of that DLL.

Secondly, it is just right and proper that a DLL is installed in the same dir as the exe that uses it. In this way when you upgrade to next version they both get replaced and you don't end up with the chaos that an old version of the program attempt to access a newer version of the DLL (which might work) or that a newer version of the program attempt to access an older version of the DLL (which most probably will not work).

HLLau's "problem" strikes me very much as a "no-problem", it isn't any problem at all, just leave it as it is and it works fine. A problem is when something doesn't work. In this case you want to make a change so that it does work. Placing the DLL with the EXE strikes me as a solution that does work and doesn't need to be changed.

Alf
0
 

Accepted Solution

by:
Grass_Hopper earned 120 total points
ID: 8056690
I'm guessing you're using Borland 3?
Try loading your project. Under "Project" - "Options",
click "Linker" tab and remove tick from "Use Dynamic RTL".
Click "ok" and do a build.
If that doesn't work... you'll have to ship the DLL with your progam.
If none of this makes sense it's because I'm asuming Borland 3 is the same or similar to Borland 5 Pro.

John
0
 

Expert Comment

by:Grass_Hopper
ID: 8056751
Oh - also, on the Packages tab in Project|Options, remove the tick from "Build with runtime packages" and rebuild.
;-)
0
 

Author Comment

by:HLLau
ID: 8070585
thanx alot!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

771 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