Could you do a short (simple please) explanation of Hard
Coded Paths and why we should not use them. It has been
a habit of mine forever and I have just found out they won't
work on Windows EP.

A couple of simple examples of how to code them in MASM32
windows would be extremely helpful to me.

Thanking you in advance.
JP Shankle
Posted on 2002-04-17 10:12:29 by shankle
hard coded paths are things like "c:\windows", "c:\program files",
and so on. There are lots of trouble. While you don't see many
people installing windows to a nondefault location (I do ;)), there's
still "c:\windows" for 9x and "c:\winnt" for NT & 2k (can't remember
which one XP uses). "c:\program files" has different names in different
windows versions, and might not even be "c:\progra~1" in all
versions - and can also be moved. There are lots of folders like
this, and most of them are even customizable per-user.

So, when you want to get the path to a special folder, start by
looking under
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
if the folder is there, use it. If not, look at the same path (except
in HKEY_LOCAL_MACHINE instead of HKCU). Hm, under win2k the
values stored there have "Common " prefixed, but the settings
ought to be stored in HKCU, so... anyway this search order has
worked pretty well for me.

You could also look at the SHGetSpecialFolderPath API.

As for your own apps, use relative paths. Ie, don't hardcode something
like "C:\MASM32\", things will work for more people when using
(properly done) relative paths.
Posted on 2002-04-17 11:17:16 by f0dder
I studied the information given but am still unable to code
a relative path.

An example would be most helpful.

Posted on 2002-04-18 21:26:27 by shankle
There are two ways to use relative path names.

1) Change directory immediately before using. In a command line console box, when you use cd to change directories, there is a call to SetCurrentDirectory. Once the current directory has been set, you can use the relative paths in any function that uses file names (including SetCurrentDirectory). Each running instance of a program has its own "current directory" (else there would be chaos).

2) Construct the full path name. You concatenate (use any of the "string cat" functions) a base directory name to the relative path, and use the new name:

include directory = "c:\secretmasm32\include"
relative path = "system\stat.inc"

full path = "c:\secretmasm32\include\system\stat.inc"

The base directory name can be stored anywhere: in an INI file, the registry, an environment variable, wherever. Windows provides GetWindowsDirectory, GetSystemDirectory, and GetSystemWindowsDirectory for retrieving directories that contain installed OS files.
Posted on 2002-04-18 22:58:26 by tenkey
You can also yank the system defined paths out of the environment variables if they're in there. This will save you from messing with the registry if you don't want to, but I don't know if those environment vars are guaranteed to be there in every Windows version.

Can anybody confirm the reliability of those env vars?

buffer db MAX_PATH dup(0)
lpszProgFilesEnv db "PROGRAMFILES",0
lpszSystemDirEnv db "SYSTEMROOT",0

; Fill buffer with the path of Program Files
invoke GetEnvironmentVariable, addr lpszProgFilesEnv, addr buffer, MAX_PATH
or eax, eax
jz _error

; Fill buffer with the path of Windows
invoke GetEnvironmentVariable, addr lpszSystemDirEnv, addr buffer, MAX_PATH
or eax, eax
jz _error
Posted on 2002-04-19 01:50:13 by iblis
Better get the paths from the registry - they should always be there,
and there are more paths stored there than in the environment
variables... since some paths are only available through the registry,
you might as well get familiar with it.
Posted on 2002-04-19 07:53:41 by f0dder
To get the path of a specific EXE, you can get the reg value from:

HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\exename

Default is the full path to the exe, and path is the directory the exe is placed in.
Posted on 2002-04-19 10:11:22 by Nordbon
I wouldn't rely on app paths... not all EXEs get a path there, and
some people (like me :)) tend to clean up app paths.
Posted on 2002-04-19 10:20:53 by f0dder

(can't remember
which one XP uses)

If you boot & install from CD, it's "?:\Windows", if you install from an existing Windows version, you can customize it. Mine is not on "C:\" anyway... :)
Posted on 2002-04-19 10:36:25 by bazik