How can I get an application's physcial path? I can't seem to find an API for it, perhaps there is another way?

BTW, thanks everybody, you've all been a great help in my project.
Posted on 2001-11-13 22:48:58 by lackluster
Use GetModuleFileName.

Posted on 2001-11-14 00:15:21 by rolft
rolft, thanks for a step in the right direction.

DWORD GetModuleFileName(
HMODULE hModule, // handle to module
LPTSTR lpFilename, // path buffer
DWORD nSize // size of buffer

How do I get the module handle? I don't own the window whos path I want.
Posted on 2001-11-14 14:27:14 by lackluster
BOOL GetModuleHandleEx(
DWORD dwFlags,
LPCTSTR lpModuleName,
HMODULE* phModule

This is supposed to return a handle to a module so I can use

DWORD GetModuleFileName(
HMODULE hModule, // handle to module
LPTSTR lpFilename, // path buffer
DWORD nSize // size of buffer

But :

Pointer to a null-terminated string that contains the name of the module (either a .dll or .exe file), or a pointer to an address in the module (if dwFlags is GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS).
For a module name, if the file name extension is omitted, the default library extension .dll is appended. The file name string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. When specifying a path, be sure to use backslashes (\), not forward slashes (/). The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process.

If this parameter is NULL, the function returns a handle to the file used to create the calling process.

So I can't get the mod handle without the filename, and I can't get teh filename without the handle? I don't own the module thus complicating things! Is there something I'm overlooking?
Posted on 2001-11-14 19:02:51 by lackluster
If you don't own the application code, then you can't use the hInstance/hModule handle alone. (instance == module, in Win32)

The hInstance handle for a running .EXE file is not unique, it must be qualified with a Process ID (or handle). GetModuleFileName uses the current process as the qualifier. (This is the process running your code.)

You might want to check out the PSAPI and ToolHelp functions (performance monitoring).
The PSAPI (process status) functions are not available on Win9x/ME.
The ToolHelp functions are not available on NT3 or NT4.
Posted on 2001-11-14 21:06:12 by tank
hmmmm........I am looking into now but perhaps there is an easier way to achieve what I want. I'm using ExtractIcon & DrawIcon to get a window's Icon on my window. I need the filename to pass to ExtractIcon as a parameter. I obviously don't own the windows who's Icons I'm trying get. Is there an easier way, or should I just keep on the route of trying to get the ModuleFileName to pass?

thanks tank
Posted on 2001-11-14 22:05:04 by lackluster
Ack! I can't find the PSAPI.lib or .inc in the masm package! Is it in there? I just want to do what ALT+TAB does with Icons.
Posted on 2001-11-15 16:38:40 by lackluster
Better use toolhelp, it's available on the most platforms.
Posted on 2001-11-15 16:59:27 by f0dder