I have tried googling, but people seem to have the same problem: we can\'t get a list of the selected files.
This is a simple piece of working code that is similar t
Here is a more complete version of the answers by Niall and Remy.
vector &filePaths;
if ( GetOpenFileName( &ofn ) == TRUE )
{
wchar_t *p = ofn.lpstrFile;
wstring path = p;
p += path.size() + 1;
if ( *p == 0 )
{
// there is only one string, being the full path to the file
filePaths.push_back( ConvertWideCharToUtf8( path.c_str() ) );
}
else
{
// multiple files follow the directory
for ( ; *p != 0 ; )
{
wstring fileName = p;
filePaths.push_back( ConvertWideCharToUtf8( ( path + L"\\" + fileName ).c_str() ) );
p += fileName.size() + 1;
}
}
}
Where we also have the function:
string ConvertWideCharToUtf8( const wchar_t *wideText )
{
int len = WideCharToMultiByte( CP_UTF8, 0, wideText, -1, NULL, 0, NULL, NULL );
char *buffer = (char *)malloc( len );
WideCharToMultiByte( CP_UTF8, 0, wideText, -1, buffer, len, NULL, NULL );
string s = buffer;
free( buffer );
return s;
}