victor_angel27
victor_angel27

Reputation: 9

self copying file to new location tchar incompatible to char

I am trying to set the destination folder , along with the desntination file path to copy itself to the new location , but however I am using strcpy , and strcat

argument of type "TCHAR *" is incompatible with parameter of type "char *"

how can I keep the same code structure , and behavior to self copy the file to the new location?


int _tmain(int argc, _TCHAR* argv[])
{
    TCHAR szFilepath[MAX_PATH];
    TCHAR szFilename[MAX_PATH];
    TCHAR szDestpath[MAX_PATH];

    /* Get the current executable's full path */
    GetModuleFileName(NULL, szFilepath, MAX_PATH);
    std::wcout << "filepath: " << szFilepath << std::endl;

    /* Extract just the name */
    GetFileTitle(szFilepath, szFilename, MAX_PATH);
    std::wcout << "filename: " << szFilename << std::endl;

    //Set the destination folder path
    strcpy(szDestpath, "D:\\");

    //Set the destination file path
    strcat(szDestpath, szFilename);

    std::wcout << "dest path: " << szDestpath << std::endl;

    // copys the file of your '.exe'

    if (!CopyFile(szFilepath, szDestpath, FALSE)) {
        std::cout << "couldnt copy the file";
    }
    else {
        std::cout << "good";
    }
    return 0;
}

Upvotes: 0

Views: 108

Answers (1)

Mayur
Mayur

Reputation: 2731

You are using TCHAR, so replace strcpy() with _tcscpy(), and strcat() with _tcscat().

Upvotes: 2

Related Questions