4

Windows CE 5 用の Visual Studio 2008 C++ プロジェクトがあり、現在実行中の実行可能ファイル自体を変更したいと考えています。

具体的には、exeファイル自体に保存されているデータを読み書きできるようにしたいと考えています。実行可能コードを変更する必要はありません (または変更したくありません)。

通常のウィンドウでは、文字列リソースとUpdateResource関数を使用できましたが、WinCE にはありません。

残念ながら、 CreateFileは、ファイルが既に使用されているため失敗します。

他に提案はありますか?

4

1 に答える 1

1

まず、なぜこれを行う必要があるのですか?他の方法でこれを行うことができるはずです。

私は特に Windows-CE に精通しているわけではありませんが、必要に応じて、ファイルをコピーし、コピーを編集し、最初のファイルを削除してから、別のファイルを実行することができます。これは非効率的な方法ですが、プログラムのスパンで 1 回か 2 回実行する必要があり、速度が問題にならない場合は、次のように実行できると思います。

#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.
}

あなたのプロジェクトで頑張ってください!

于 2012-07-28T15:55:57.337 に答える