如何删除 C++ 中 Exe 名称的硬编码应用?
我正在使用 Codegear C++ 开发表单应用程序。代码中的所有 Exe 名称都是硬编码的。 Exes 存在于一个公共驱动器中。删除硬编码的最佳方法是什么? 使用.ini 文件好吗?如果是的话,该怎么办?我尝试使用.ini文件,如下所示,但它不起作用:
settings.ini文件:
[PathSettings] exe1="R:\\exe1" exe2="R:\\exe2" exe3="R:\\exe3"
在我添加的代码中:
#define PATH_INI "settings.ini" //.ini in the same folder
获取exes的路径
GetPrivateProfileString("PathSettings", "exe1", "", pathExe, 1000, PATH_INI);
//to get the exe1 path into pathExe
GetPrivateProfileString("PathSettings", "exe2", "", pathExe, 1000, PATH_INI);
//to get the exe2 path into pathExe
I am working on Form application using Codegear C++. All Exe names in the code are hard coded. The Exes are present in a common drive. What is the best way to remove hard coding?
Is it good to use .ini file? If yes, how to go about it? I tried using .ini file, as follows and it did not work:
settings.ini file:
[PathSettings] exe1="R:\\exe1" exe2="R:\\exe2" exe3="R:\\exe3"
In the code I added:
#define PATH_INI "settings.ini" //.ini in the same folder
To get the path of exes
GetPrivateProfileString("PathSettings", "exe1", "", pathExe, 1000, PATH_INI);
//to get the exe1 path into pathExe
GetPrivateProfileString("PathSettings", "exe2", "", pathExe, 1000, PATH_INI);
//to get the exe2 path into pathExe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论