简体   繁体   English

在Windows中是否有一个简单的C ++程序文件/程序文件(x86)指令?

[英]Is there a simple Program Files/Program Files (x86) directive for C++ in windows?

I am currently hard-coding the path to my application as follows: 我目前正在硬编码我的应用程序的路径如下:

const char* OriginCopyFile = "C:\\Program Files (x86)\\i-cut\\i-cut\\Origin_copy.txt";

This application is going to be running in both 32 and 64 systems. 该应用程序将在32和64系统中运行。 How can I detect the path without the file name in order to reuse it with several files and make it portable between architecture. 如何在没有文件名的情况下检测路径,以便将其与多个文件一起使用,并使其在架构之间可移植。

You can use GetModuleFileName to get the path to your executable, wherever it was installed or even moved later. 您可以使用GetModuleFileName获取可执行文件的路径,无论它在何处安装,甚至以后移动。 You can then PathRemoveFileSpec to remove the executable name (or strchr() and friends if you want to support earlier versions than Windows 2000). 然后,如果要支持早于Windows 2000的版本,则可以使用PathRemoveFileSpec删除可执行文件名(或strchr()和朋友)。

SHGetSpecialFolderPath(CSIDL_PROGRAM_FILES) will at least give the path to the program files directory. SHGetSpecialFolderPath(CSIDL_PROGRAM_FILES)至少会给出程序文件目录的路径。 You'll have to deal with adding the rest of the path and file name. 您将不得不处理添加其余路径和文件名。

You can use environment variables for this: 您可以使用环境变量:

#include <stdio.h>
#include <stdlib.h>

int _tmain(int argc, _TCHAR* argv[])
{
char* programFiles = getenv("ProgramFiles(x86)");   
if (programFiles==NULL)
{
    programFiles = getenv("ProgramFiles");
}

printf(programFiles);

return 0;
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C++ | 如何删除位于 (C:\Program Files (x86)) 的文件夹中的文件 - C++ | How can i delete files in a folder located in (C:\Program Files (x86)) LNK1104: 无法打开文件 &#39;C:\\Program Files (x86)\\Windows Kits\\10\\\\lib.obj&#39; - LNK1104: cannot open file 'C:\Program Files (x86)\Windows Kits\10\\lib.obj' 为什么 FOLDERID_ProgramFiles 返回“C:\\Program Files (x86)”? - Why does FOLDERID_ProgramFiles return “C:\Program Files (x86)”? 错误:未找到导入的项目“C:\\ Program Files(x86)\\ MSBuild \\ Microsoft \\ WindowsXaml \\ v11.0 \\ Microsoft.Windows.UI.Xaml.Cpp.targets” - Error: The imported project “C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v11.0\Microsoft.Windows.UI.Xaml.Cpp.targets” was not found 为什么编译64位程序时CMake默认为Program Files x86? - Why does CMake default to Program Files x86 when compiling 64 bit program? 吉普错误! 堆栈错误:`C:\\Program Files (x86)\\MSBuild\\12.0\\bin\\msbuild.exe` 失败,退出代码:1 - gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1 “package System.Net.Http 版本 4.1.1 在 C:\NProgram Files (x86)\Microsoft SDKs 中找不到 - "The package System.Net.Http with version 4.1.1 could not be found in C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\." 为什么为x64平台编译的c ++程序比为x86编译慢? - Why c++ program compiled for x64 platform is slower than compiled for x86? 如何从32位WOW进程获取Program Files文件夹路径(不是Program Files(x86))? - How to get Program Files folder path (not Program Files (x86)) from 32bit WOW process? Qt可执行文件在发行文件夹中运行-程序文件(x86)中的运行时错误 - Qt executable running in release folder - Runtime error in Program Files (x86)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM