mardi 22 décembre 2020

C++: Problem of Combine String in std::string

I have a code for Read the log file to combine the string.

and It usually works well, but I found a case where doesn't work:

  1. My code work well on the path below immediately after build. path : {project directory}\bin\x32\text.exe (builded file)

  2. However, if I move a builded folder to another location and execute that, the string combine doesn't run.

This is my c++ code:

void MakeCommandWithLogFile()
{
    CHAR myDocumentsPath[MAX_PATH];
    HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocumentsPath);

    string myDocumentsString(myDocumentsPath);
    string logFilePath = myDocumentsString + "\\Project\\data.log";

    string data

    // read log file
    wstring dataW;
    wifstream ifs(logFilePath);
    while (getline(ifs, dataW))
    {
        // copy wstring to string(t)
        data.assign(dataW.begin(), dataW.end());
    }

    string command;
    command = "init \"" + data + "\"";
}

When I execute on a build folder, the result is:

command : init "C:\Users\user\Desktop\crackme2.exe"

If I move the builded project to another path, the results are as follows.

command : 

The contents in the log file are as follows. (data.log with UTF-8 format)

C:\Users\user\Desktop\crackme2.exe

When I checked in the debugging environment, this code command = "init \"" + data + "\""; is not working.

There are no errors or warnings, as well as no results.

my desktop is using a windows 10 os.

Please give me some advice.

Aucun commentaire:

Enregistrer un commentaire