Jump to content
  • Advertisement
Sign in to follow this  
Seriema

dll not finding another dll in the same dir - Solved!

This topic is 5409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

thx everyone, my problems solved now! but I'll leave the original post for records. Hidy ho! I have a app, ExtractorManager.exe, that uses a DLL; Registry.dll. And I have a DLL, ShellExtension.dll, that uses Registry.dll. They're all in the same dir. ExtractorManager.exe find's Registry.dll without any problem. But ShellExtension.dll can't find Registry.dll, although they're in the same dir. Since ShellExtension.dll is a.. shell extension *bet you couldn't see that coming?*, it's called by explorer.exe that's usually in c:\Windows. Ie making the working directory c:\windows, wheres my files are in a completely different directory :( How can I make a DLL find's it's own path? The only functions I've found return the working path. I just need to access Registry.dll that's in the same folder. Thanx for any tips. [Edited by - Seriema on September 28, 2004 5:14:13 PM]

Share this post


Link to post
Share on other sites
Advertisement
Windows has a very specific method for finding libraries on the system. You can find the order here.

You can put the dll in one of these directories for Windows to find it. Or you could do something like create a registry key that says where the dll is located (like COM dlls do) and have the shell extension locate it through the registry.

Magius

Share this post


Link to post
Share on other sites
GetModuleFileName() might do it, if you happen to have a handle to yourself, which it appears can be obtained by using GetModuleHandle(), using the name of the module, which in your case I suppose would be "ShellExtension.dll".

Share this post


Link to post
Share on other sites
Thanks everyone for your responces.

Magius, according to that link the second place it looks is in the same dir. Which should work =/ Using the registry etc could solve the problem, unless I've encapsuled all my registry handling into: Registry.dll >_<

Agony, I'll try that.

antareus, yeah but there are some problems with that. Check my answer to Magius.


lib = LoadLibrary( ".\\Registry.dll" ); // I have also tried without the .\\ and tried with ./

It just returns NULL. And according to this and that, my loading should succeed since they're all in the same dir.

Share this post


Link to post
Share on other sites
I don't see the problem. Why can't you just call LoadLibrary("C:\\Projects\\DLLFun\\Registry.dll"); instead of trying to weasel your way out using relative paths?

Share this post


Link to post
Share on other sites
antareus, because this is a program I want to distribute. So I won't know where they installed the path unless I wrote it in the registry, and my registry functionality is in Registry.dll. I could hack a bit and check the registry. But since they're all in the same dir, that feels weird.

Share this post


Link to post
Share on other sites
It makes sense that Windows wouldn't find your dll in the search path indicated in MSDN. Explorer.exe would be considered the current executable module for the current process and the current directory is probably C:\Windows or something of the like as you indicated. If you want to be location agnostic and be found by the system (or yourself), you have two choices:

1. Put the DLL in one of the directories known to be in the search path (ex. C:\Windows\system32).

2. Create a registry key like COM dlls do and read this registry key. It takes very little code to open a specific registry key and look at one specific registry value - I know you have all of your registry functionality encapsulated into that library, but in this case it might be worth having a registry stub function somewhere else that can locate this dll properly.

Magius

Share this post


Link to post
Share on other sites
GetModuleFileName() will give you the location of the current module. Once you get this you can figure out all the other paths and use absolute paths to load your DLLs. Don't write to the registry or anything complicated like that.

And please don't litter system32 with your DLLs. No program is so important that it should go into a system folder.

Share this post


Link to post
Share on other sites
Magius, thanx for your responces. They were very helpful. But read on.

Agony, as promised; I did test your method. And guess what... IT WORKED!! omg I'm sooo happy now! =D

Antareus, yes as I said to Agony (which had posted the same tip) I did try it out. And it worked!

Here's the code snippet that made it work!

void AbsolutePath(LPCTSTR relativePath, LPTSTR result, size_t resSize)
{
HMODULE hModule = GetModuleHandle("ShellExtension.dll");
assert( hModule );
DWORD len = GetModuleFileName( hModule, result, resSize );
assert( len < resSize );
BOOL res = PathRemoveFileSpec(result);
assert( res == TRUE );
HRESULT hRes;
if( relativePath[0] != '.' && relativePath[0] != '\\' )
{
hRes = StringCchCatN(result, resSize, "\\", 2);
assert( hRes == S_OK );
}
hRes = StringCchCatN(result, resSize, relativePath, _tcslen(relativePath)+1);
assert( hRes == S_OK );
}




TCHAR buff[MAX_PATH];
AbsolutePath(".\\Registry.dll", buff, MAX_PATH);
// buff now holds the absolute path to Registry.dll! =D|<

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!