开发者

File redirection not working if I SetCurrentDirectory to C:\Program Files in 32 bit app on Win7 64 bit, should it not navigate to (x86) folder?

开发者 https://www.devze.com 2023-04-12 19:01 出处:网络
Here is my test code below. //This correctly prints C:\\Program Files from 64 app on 64 bit Win7 and //C:\\Program Files (x86) 32 bit app on 64 bit Win7

Here is my test code below.

//This correctly prints C:\Program Files from 64 app on 64 bit Win7 and
//C:\Program Files (x86) 32 bit app on 64 bit Win7
system("echo %PROGRAMFILES%\n");

BOOL ret = SetCurrentDirectory("C:\\Program Files\\");

char szFolder[512] = {0};
GetCurrentDirectory(512, szFolder);

//folder is printed as C:\Program Files from 32 bit app on 64 Win7! Why?
cout << "Current folder now: " <<开发者_如何学Python szFolder << endl;

Reason for writing code is to test what would happen if 32 bit InstallShield set path to C:\Program Files. We want the path to be set to C:\Program Files on 32 bit OS and C:\Program Files (x86) on 64 bit OS. I assumed that the Windows File System Redirection feature would ensure this happened?

Basically, we have to locate a 32 bit library which will be in (x86) folder. We were hoping that setting to C:\Program Files would be redirected correctly so we don't have to worry about it?

Why is SetCurrentDirectory not being redirected? I am testing on 64 bit Windows 7. Application is compiled using MS VSC++ 2008.


This is quite simple. The Program Files directory is not subject to file redirection.

You probably would be best using the CSIDL_PROGRAM_FILES and CSIDL_PROGRAM_FILESX86 CSIDL values but you'll have to work out for yourself whether you need the x64 or x86 folders.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号