GetModuleFileName & CopyFile
Code:
int main(void){
char path[MAX_PATH];
HMODULE hModule = GetModuleHandle(NULL);
if (hModule != NULL)
{ GetModuleFileName(hModule, path, (sizeof(path)));
}
CopyFile(path, "C:\\xyz", 0);
}
With GetLastError() I now know thats because GetModuleHandle outputs the path with one /, and copyfile requires // to not mix it with an escape sequence. But how could I fix that? Or is there another way to make the exe get his own path and copy itself into another directory?
And no
I dont want static paths.
//EDIT
found a solution.
Code:
char szFilepath[255];
char szFilename[255];
char szDestpath[255];
GetModuleFileName(NULL, szFilepath, 255);
GetFileTitle(szFilepath, szFilename, 255);
strcpy_s(szDestpath, "C:\\xyz\\");
strcat_s(szDestpath, szFilename);
CopyFile(szFilepath, szDestpath, FALSE);
But I'm not understanding why mine isn't working and this code is? Somebody minds explaining?