Win32 API: Working Dir

Started by
11 comments, last by rmsimpson 17 years, 12 months ago
hi, I didn't find it: What Win32 functions returns the working dir of a process (like getcwd)? bye Chris
Advertisement
GetCurrentDirectory
GetCurrentDirectory

I'm not sure how to find it out for any other process.
Thanks!

GetCurrentDirectory is useful. But it would be really interesting if you can get it for any process.
I suspect that the only way to get another processes working directory would be to inject a DLL into the process and call GetCurrentDirectory from there.

Why would you need to know another processes working directory anyway?
Here's the problem:

I'm writing a DLL which gets loaded in an isapi filter (I don't have the source). Now I load a DLL myself. But it can only be found if it is located at "C:\WINDOWS\system32" (because the working dir of my dll is "C:\WINDOWS\system32" I guess) which I don't want. I want to put the DLL in the same directory as the isapi filter.
I thought I could get the working dir of the parent process to solve the problem...

Any ideas?
I'm not sure, but I perhaps you could use EnumProcessModules to find the modules for a process and use GetModuleFileName (or GetModuleFileNameEx) to find their full path.
If that is what you're after.
A DLL doesn't have a working directory, since it's not a process. If a DLL is loaded into a process, then it gets the parent processes working directory.
Is it not an option to let the user install it into the correct directory? If not, does the isapi filter have any registry entires saying where it's installed?

Using EnumProcessModules might work, but if the application changes it's working directory, that won't work properly.

How is this all working? Do you have an installer to install your DLL or something? You can't just run a DLL (Well, aside from the rundll command)...
Quote:Original post by Zoomby
But it can only be found if it is located at "C:\WINDOWS\system32" (because the working dir of my dll is "C:\WINDOWS\system32" I guess) which I don't want.

This is probably because Windows will always look for libraries in the system folders, or indeed in the same folder as the application is running.
Quote:You can't just run a DLL (Well, aside from the rundll command)?

You can load a DLL with the LoadLibrary Function. Did you mean that?

This topic is closed to new replies.

Advertisement