大佬教程收集整理的这篇文章主要介绍了c – 修改自身的正在运行的可执行文件,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
具体来说,我希望能够读取/写入exe文件本身存储的一些数据.我不需要(或希望)修改可执行代码.
在常规窗口中,我可以使用字符串资源和UpdateResource函数,但在WinCE中不存在.
遗憾的是,CreateFile因文件已被使用而失败.
有人有任何其他建议吗?
@H_607_2@
我对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. }
祝你的项目好运!
@H_607_2@ @H_607_2@以上是大佬教程为你收集整理的c – 修改自身的正在运行的可执行文件全部内容,希望文章能够帮你解决c – 修改自身的正在运行的可执行文件所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。