November 28, 2014
Hot Topics:

Using RAPI to Find Remote Files

  • July 26, 2004
  • By Nancy Nicolaisen
  • Send Email »
  • More Articles »

In this lesson, you'll learn the uses of a RAPI powertool, the function CeFindAllFiles. This function has no CE side analog. To create powerful, panoramic CE file handling capabilities, our best bet is to work from the desktop side, using RAPI.

Initializing The Remote File Access Page

For this lesson, we return to the RAPI Demo example program. The code for this program is available on the Developer.com Web site. Let's take a look at the Remote File Access page of the application's property sheet control.

The Remote File Access page is slightly more complicated than the System Status page (the substance of our last lesson), owing to the fact that it has more controls and is somewhat more interactive.



Click here for a larger image.

Figure 1: The Remote File Access Page of the RAPI Demo Property Sheet Control

We'll begin by looking at the modifications made to the header file for the class, RemoteFileAccessPage.h. Using the resource editor and ClassWizard, a member variable was created for each of the dialog's controls. The variables are of the same type as the controls they encapsulate.

// Dialog Data
   //{{AFX_DATA(CRemoteFileAccessPage)
   enum { IDD = IDD_FILE_ACCESS_DIALOG };
   CButton     m_GetCEOID;
   CButton     m_GetLastWriteTime;
   CButton     m_GetFoldersOnly;
   CButton     m_GetCreationTime;
   CButton     m_UpdateFilesList;
   CListBox    m_SearchPath;
   CListBox    m_FilesList;
   CEdit       m_FileInput;
   //}}AFX_DATA

Here's how we implement the behavior of the Remote File Access page. First, we have to initialize the control variables, and after that we have to respond with the appropriate information when the user presses the "Update File List " button. The initialization step is handled in OnInitDialog().

We insert two search path strings in the m_SearchPath. list control Notice the double backslash characters in the path strings. In C and C++, a single backslash character is interpreted as the first character of an "escape sequence." An example of an escape sequence is the tab character, represented as "\t". By convention, "\\" is interpreted as a single backslash character.

We initialize the list control selection to the first visible string (0th ordinal), and we clear all of the checkbox controls. The check box controls correspond to items of file information that we can optionally retrieve.

BOOL CRemoteFileAccessPage::OnInitDialog()
{
   CPropertyPage::OnInitDialog();


   //Insert Search List Items
   m_SearchPath.InsertString( -1, "\\*.*" );
   m_SearchPath.InsertString( -1, "\\Windows\\*.*" );

   //Set search list selection
   m_SearchPath.SetCurSel( 0 );

   //Clear File Attribute Flag members
   m_GetLastWriteTime.SetCheck(0);
   m_GetCreationTime.SetCheck(0);
   m_GetFoldersOnly.SetCheck(0);
   m_GetCEOID.SetCheck(0);

   return TRUE;  // return TRUE unless you set the focus to a control
                 // EXCEPTION: OCX Property Pages should return FALSE
}

The actual work of the Remote File Access page isn't done until the user presses the "Update File List" button. In the OnUpdateFileButton() member, first we clear the list control with a call to ResetContent(), and then we initialize the RAPI subsystem with CeRapiInit().

////////////////////////////////////////////////////////////////////
// CRemoteFileAccessPage message handlers

void CRemoteFileAccessPage::OnUpdateFileButton() 
{

   WCHAR       wszFileName[MAX_PATH];

   //clear current list
   m_FilesList.ResetContent();

   HRESULT hr = CeRapiInit();
   if ( hr != ERROR_SUCCESS )
      { return; }

Next, we create a Unicode search path string, based on the selection in the list control, m_SearchPath. Notice that we use the L macro to prefix the literal string that we want to render in Unicode. In earlier examples, we used the TEXT macro for this purpose. The TEXT macro doesn't work in MFC applications unless they are specifically enabled with Unicode preprocessor definitions.

Programming Tip: Use the L macro to create Unicode literal strings in MFC applications. Here's an example of the use of the L macro:
L"This is a Unicode literal string"
   LPCE_FIND_DATA pFindDataArray = NULL;
   DWORD dwFoundCount = 0;

   int iSel = m_SearchPath.GetCurSel();
   if( iSel == 0 )
   {
      wcscpy(&wszFileName[0], L"\\*.*" );
   }
   else
   {
      wcscpy(&wszFileName[0], L"\\Windows\\*.*" );
   }




Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel