parse a NULL- Separated string

Using windows "GetOpenFileName"  with the OFN_ALLOWMULTISELECT flag set returns a null seperated string.
Is there a standard routine for parsing this to extract each filename.
MCoferAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
freewellConnect With a Mentor Commented:
MFC way for parsing.

int nCount = 0;
CString strText;

while(AfxExtractSubString(strText,pszMultiFile,nCount++,_T(0x00)) && strText.GetLength() > 0)
{
      TRACE("File %d: %s\r\n",nCount, strText);
}
0
 
jkrCommented:
No, there is no such standard routine. But, writing one is not too difficult:

#include <list>
#include <string>
using namespace std;

UINT GetFilesFromMultiSelect ( char* pszMultSel, list<string>& r) {

    UINT unCount = 0;
    char* pc = pszMultSel;

    while ( strlen ( pc)) {

          r.push_back ( string ( pc)); // found a file, add it to the list of files

          pc = memchr ( pc, 0); // search for the next NULL char,

          pc++; // Advance to the next file entry ('strlen()' will return 0 at the end)

          ++unCount;
    }

     return unCount;
}
0
All Courses

From novice to tech pro — start learning today.