Checking if a file exists on a 64 bit Vista machine with a 32 bit program
So, I have a 32 bit program which needs to check if files exist. However, the locations (which can come from开发者_C百科 both shortcuts and the registry) often make use of Environment Strings. I use the ExpandEnvironmentStrings api to expand them, then check if the file exists. However, because it is a 32-bit application (note environmental strings emulation), the paths are expanded to the wrong locations in some cases. As I don't know if paths I'm given are 32 bit or 64 bit, one simple solution is to just expand the relevant environmental strings (ProgramFiles and CommonProgramFiles) using both the 64bit locations and the 32bit locations manually. However, this feels a bit hacky. Is there a better way?
Perhaps File System Redirector will be helpful. In particular see Wow64DisableWow64FsRedirection Function and its close friends described there.
Even so you'll probably need to do some checks to determine which strings you need to expand and whether you want the 32 or 64-bit expansion. For that I suspect a simple table of strings won't help. As you say %ProgramFiles% might mean the 32-bit path in some cases and the 64-bit path in others.
精彩评论