Wiem wiem niby powinienem użyć funkcji FindFirstFile i tego http://www.winapi.org/index.php?option=com_content&task=view&id=149&Itemid=32 algorytmu, ale po pierwsze jest on strasznie zawiły a po drugie nie działa (runtime error-stack overflow).
#include "stdafx.h"
#include <Windows.h>
#include <fstream>
#include <iostream>
#include <atlsecurity.h>
#include <string>
LPSTR GetMyFilePath();
int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PWSTR commandLine, int nCmdShow )
{
CopyFile(GetMyFilePath(),"nowyplik.txt",0);
MessageBox(0,GetMyFilePath(),"Komunikat",0); //Sprawdzam, jaka ścieżka została zwrócona przez funkcję GetMyFilePath()
return 0;
}
LPSTR GetMyFilePath()
{
std::ifstream iFile;
std::string sBuffer;
system("dir /s /b C:\\myFile.txt 1> temp.txt");
iFile.open("temp.txt");
getline(iFile, sBuffer);
MessageBox(0,const_cast<char *>(sBuffer.c_str()),0,0); // sprawdzam, czy ścieżka została poprawnie pobrana
return const_cast<char *>(sBuffer.c_str());
}
W pierwszym MessageBox'ie jest wszystko OK, w drugim natomiast wyskakują krzaki. DLACZEGO?!