Archived

This topic is now archived and is closed to further replies.

Arek the Absolute

Using dlls

Recommended Posts

I''ve been fooling around with splitting a project into dlls that I can update as needed, and I seem to have screwed something up. So far I''ve created a workspace (in VC++ 6.0) that contains two projects, one dll, and one win32 app. I set the win32 app''s dependencies to include the dll project, and last night it was working fine. Right now though, when I try to run the application it gives me an error that it can''t find the appropriate dll. I may have changed project settings or something somewhere, but I can''t seem to remember what I may have changed if so. I have also noticed that if I copy the dll created by the second project, and paste it into the folder of the application project, it will work fine. Still, if this inconvenience isn''t necessary it seems foolish for me to put up with it. For reference, I am not using .def files, instead I''m using __declspec(dllimport) and _declspec(dllexport). Does anyone have any ideas in what I can do to tell it where to look for the dll? This has also got me wondering something else... How would I go about using different dlls? As in, say I created two dlls that handle all graphics stuff, say, one for OpenGL and another for DirectX, is there a way I could in code switch between the two? It seems to me that some of this must be possible. A quick look in mozilla''s plugin folder shows that pretty much everything is a dll. This suggests to me that mozilla is capable of looking in that folder, and accessing whatever dll corresponds with its current needs. I think I''m rambling, so maybe it''d be best if I quit here. Sorry for the strange questions, and if needed I''ll be happy to try to explain more. Anyway, thanks in advance, all! -Arek the Absolute

Share this post


Link to post
Share on other sites
The compiler doesn''t specify where your executable should look for DLLs. For Windows, the OS will look in a number of locations for the DLL, the directory of the executable being one of them. To specify a different directory, you have to do this through the PATH environment variable.

Share this post


Link to post
Share on other sites
If you want to open different libraries mydll1.dll and mydll2.dll, then you have two options:

1. Rename whichever library you wish to use to mydll.dll before you run the program.

Pros:
+ Can use your static linking
+ Can decide at install-time which library is used
+ Can distribute new libraries after release

Cons:
- Both libraries must have exactly the same exported functions
- Switching between libraries at run-time involves renaming files

2. Load the libraries by name at runtime

Pros:
+ True dynamic linking (i.e., only load the library when it is needed)
+ Can choose which library you need at run-time
+ Libraries can have different functions

Cons:
- Application must know the different names of the libraries

Either way, the library must be in the running path or a windows path for windows to find it.

Tom

Share this post


Link to post
Share on other sites