[Win32] Loading DLL's from a different directory
I''d like to be able to implicitly load a DLL from a directory not in the system path.
Reason for this is as follows:
Directories:
\Game
\Game\Sound
I load Sound.dll using GetProcAddress. Sound.dll is my DLL. It works fine. However, sound.dll implicitly links in fmod.dll.
Run game and I get an error, fmod.dll cannot be found, it''s sitting in Sound.dll.
Now since fmod.dll is beinf implicitly loaded in to the address space of sound.dll I''d have spected it to be a ''current directory'' however this doesn''t seem to be the case.
Is there a way around this. I love structure and I''ve love to put my DLL where I want them. Is there a way to ''add'' a directory to the system path while my app is running perhaps?
Chris Brodie
http:\\fourth.flipcode.com
If you have MSVC, you can delay-load your DLLs and override the hook proc to manually load fmod.dll if it can''t be found in the default search path.
quote:
Now since fmod.dll is beinf implicitly loaded in to the address space of sound.dll I''d have spected it to be a ''current directory'' however this doesn''t seem to be the case.
sound.dll does not have it''s own address space. Only processes have their own address space.
Where is fmod.dll located? It needs to be in one of the search paths used by Windows or in the same directory as your app (the same directory as sound.dll may also be ok but I''m not sure about that).
and thats the problem. fmod.dll is in the same directory as Sound.dll and it is not found. fmod is only found when it''s in the same directory as the exe(I won''t even bother with anywhere else in the path).
Is there any way around this?
Chris Brodie
http:\\fourth.flipcode.com
Is there any way around this?
Chris Brodie
http:\\fourth.flipcode.com
I'd put both DLL's in \Game\Sound and add \Game\Sound to the PATH enviroment variable.
Adding the path to the PATH variable while the program is running is not going to work since the DLL's are mapped before execution is passed to your entry point.
You could try creating a small 'startup' program that adds the path (if not already there) and then launches your app, or create an install package.
You can use putenv and getenv to add/edit enviroment variables
[edited by - Solo on June 5, 2002 11:32:27 AM]
[edited by - Solo on June 5, 2002 11:36:15 AM]
Adding the path to the PATH variable while the program is running is not going to work since the DLL's are mapped before execution is passed to your entry point.
You could try creating a small 'startup' program that adds the path (if not already there) and then launches your app, or create an install package.
You can use putenv and getenv to add/edit enviroment variables
[edited by - Solo on June 5, 2002 11:32:27 AM]
[edited by - Solo on June 5, 2002 11:36:15 AM]
LoadLibraryEx with the LOAD_WITH_ALTERED_SEARCH_PATH flag when you load sound.dll
Is that make sense?
Is that make sense?
Oops, I forgot that sound.dll was being loaded explicitly so scratch that part about the DLL''s being loaded before execution is passed to your entry point.
Solo,
You got it. _putenv seems to work just the way I want. When I load Sound\Sound.dll I grab the relative path, add it to the current path eg c:\game\mygame\sound\ and add that to the PATH environment variable. That way a componenet I load will have access to DLL''s it needs.
Works great!
Chris Brodie
http:\\fourth.flipcode.com
You got it. _putenv seems to work just the way I want. When I load Sound\Sound.dll I grab the relative path, add it to the current path eg c:\game\mygame\sound\ and add that to the PATH environment variable. That way a componenet I load will have access to DLL''s it needs.
Works great!
Chris Brodie
http:\\fourth.flipcode.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement