首先,你爲什麼需要這樣做?你應該可以用其他方法做到這一點。
我對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.
}
祝你的項目!
這是完全需要的還是你不能在磁盤上存儲平面文件? – sean 2012-07-24 20:45:34
聽起來對我來說似乎是基於理解不足,而不是實際需求。我可能是錯的,但是這個的有效用途很少。 – 2012-07-24 20:53:12
真正的核心解決方案是修改當前的內存轉儲(您對PE頭和段有多少知道?),然後將其轉儲到文件(或複製本身並修改...),但我懷疑有什麼辦法你可以在不殺死一個進程並創建另一個進程的情況下(可以通過在終止時執行bat腳本交換文件)來實現這一點。 – Vyktor 2012-07-24 20:58:27