C++ Winapi项目访问问题

发布于 2025-02-14 00:45:10 字数 544 浏览 3 评论 0原文

我有一个C ++ Winapi项目,该项目在VS(调试和发布)中正常运行,该应用程序在文本文件start.txt中写入一些数据,并将某些图像复制到目录“位图”,文本文件和目录都位于应用程序的主要目录,但是当我在C:\ Program Files(X86)\或C:\ Program Files \中使用设置程序安装应用程序时,文本文件start.txt和文件夹都“位图”仅读取,无法用于将数据存储在它们中的应用程序,因此该应用程序无法正常运行,并且显示一些错误如下:(

CIMG :: fopen():无法打开文件'C:\ Program Files。 \ application name \ bitmaps \ user1.bmp带有模式'wb')))) 这是因为目录中没有图像而被理解的,我还检查了文本文件start.txt也空了

我在某个地方读到Windows系统不允许在“程序文件”和“程序文件(x86)”目录中编写数据的地方。数据应在AppData或其他某个地方通过应用程序编写

,如果我以管理员的身份运行该应用程序,则该应用程序确实可以正确运行

。应用在安装后将数据存储到而无需运行应用程序的情况下吗?

I have a C++ WinApi project which works fine in VS (Debug and Release) , the application writes some data in a text file start.txt and copies some images to a directory "bitmaps" , both the text file and the directory are located in the Application's main Directory, but when I install the application with a setup program in C:\Program Files (x86)\ or in C:\Program Files\ , both the text file start.txt and the folder "bitmaps" become read only , not accessible for the application to store data in them, so the application does not function correctly and some error show like:

((cimg::fopen(): failed to open file 'C:\Program Files\application Name\bitmaps\user1.bmp with mode 'wb'))
this is understood because there are no images in the directory, I checked also the text file start.txt also empty

I have read somewhere that Windows System does not allow writing data in the "Program Files" and "Program Files (x86)" directories and data should be written in AppData or somewhere else by applications

by the way , the application does run correctly if I run it as administrator

is there a way to set permission to the directory and the text file to make them accessible (writable) for the application to store data into without running the application as administrator after installing it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七七 2025-02-21 00:45:10

最好的解决方案是存储应该在AppData中存储它们的数据,然后将解决该问题

以获取AppData文件夹的路径:

Appdatapath= getenv("appdata"); // geting AppData path
Appdatapath +=("\\yourappData"); // adding a new directory for your 
                                // application where data are written

The best solution to this is to store data where they should be for example in the AppData , the problem then will be solved

to get the path of AppData folder :

Appdatapath= getenv("appdata"); // geting AppData path
Appdatapath +=("\\yourappData"); // adding a new directory for your 
                                // application where data are written
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文