ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6
part 7


3 - File Scanning and Matching

Now on to the code - the dialog is similar to ones we've worked with previously (although you might want to look over the source to familiarize yourself again), but the section new to us is where we create the list of data to display:


  ebo_enumerator_t e; 
  e.index=-1; // init search 
  while ( ebo_next_object(&e)>=0 && m_totalEntry<c_maxEntry-1 ) 
  { 
    if (0==stricmp(e.name.extension,ext)) // one of ours? 
    { 
      // add to list 
      m_entry[m_totalEntry]=new ebo_enumerator_t; 
      memcpy(m_entry[m_totalEntry],&e,sizeof(ebo_enumerator_t)); 
      ++m_totalEntry; 
    } 
  } 

ebo_next_object() simply takes the index stored in the object passed in, adds one to it, and uses it as a lookup into the file list. Although there is an ebo_first_object() function that can be used to initially start searching, it is just a wrapper for setting the index to -1 and calling ebo_next_object(), and so using the single function in this way makes the code much cleaner. (As a further point, the MMC equivalent did not exist in standalone mode, and it was only after communicating with Franklin about this that this streamlined way of coding the calls came to light).

Each call to ebo_next_object() returns the next file object, and when all done returns a negative value. This loop simply adds the structures to an array for later display in a list. The array is currently set to 200 items, but it can easily be enlarged or made dynamic; however this limit should handle most situations.

Adding MMC support in addition to this dialog is easy, a matter of setting the object's index to -1 again, and calling the MMC equivalent of ebo_next_object(), named ebo_next_xobject():

  e.index=-1; // init search
  while ( ebo_next_xobject(&e)>=0 && m_totalEntry<c_maxEntry-1 )
  {
    if (0==stricmp(e.name.extension,ext)) // one of ours?
    {
      // add to list
      m_entry[m_totalEntry]=new ebo_enumerator_t;
      memcpy(m_entry[m_totalEntry],&e,sizeof(ebo_enumerator_t));
      ++m_totalEntry;
    }
  }

Following this, you have a complete array of matched files, which is then sorted and presented to the user to pick from. Note that the criteria for inclusion here are a matching extension, but you could modify the program to use any file data you wished for filtering.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice