c – 修改自身的正在运行的可执行文件
发布时间:2020-12-16 07:00:48 所属栏目:百科 来源:网络整理
导读:我有一个用于 Windows CE 5的Visual Studio 2008 C项目,我希望当前运行的可执行文件可以自行修改. 具体来说,我希望能够读取/写入exe文件本身存储的一些数据.我不需要(或希望)修改可执行代码. 在常规窗口中,我可以使用字符串资源和UpdateResource函数,但在Win
我有一个用于
Windows CE 5的Visual Studio 2008 C项目,我希望当前运行的可执行文件可以自行修改.
具体来说,我希望能够读取/写入exe文件本身存储的一些数据.我不需要(或希望)修改可执行代码. 在常规窗口中,我可以使用字符串资源和UpdateResource函数,但在WinCE中不存在. 遗憾的是,CreateFile因文件已被使用而失败. 有人有任何其他建议吗? 解决方法
首先,你为什么需要这样做?您应该可以使用其他方法执行此操作.
我对Windows-CE并不是特别熟悉,但是如果需要,你可以复制文件,编辑副本,删除第一个,然后运行另一个.这是一种效率低下的方法,但是如果你只需要在程序范围内执行一次或两次并且速度不是问题,我想你可以这样做: #include <iostream> #include <fstream> #include <string> using namespace std; int main(int argc,char * argv[]) { // Check if this IS the copy: if (argv[0].find(argv[1]) != string::npos) { system("taskkill -IM myOLDfile.exe"); // Stop the old one running,system("del myOLDfile.exe"); // Then delete it. } ifstream myself(argv[0]); // argv[0] is the program itself string fullcode; string line; if (file.is_open()) { while (file.good()) { getline(myself,line); line.append("n"); fullcode.append(line); } } myself.close(); // Do whatever you need to do to the code here. ofstream newcode("myNEWfile.exe"); newcode.write(fullcode); newcode.close(); system("myNEWfile.exe myNEWfile.exe"); // Starts new file. Also,not a typo. } 祝你的项目好运! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Mapxtreme 64位开发,未能加载文件或程序集,或它的某一个依
- nosql – Cassandra – 如何检索CF中的所有密钥(随机分区程
- Swift学习—数据类型
- Elixir Ecto: 使用Arbor在Postgresql中实现邻接列表与树的遍
- ruby – 如何进行Dir.glob但排除目录?
- c# – Entity Framework中的奇怪行为Linq中的字符串EndsWit
- windows上如何安装Sqlite
- jasper-reports – 如何在“单一文本字段”中显示jasper报告
- blazeds实现java到flex类映射
- ruby-on-rails – 如果超过X秒,则退出线程