September 2, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Understanding Mobile Data Synchronization: Creating Custom File Filters

  • September 1, 2005
  • By Alex Gusev
  • Send Email »
  • More Articles »

Registering the File Filter

Well, you have successfully developed your great file filter and you can be proud of it. The only thing left is to kindly inform MS ActiveSync that the new filter exists and how to use it. You have several options about to do it:

  • Create a separate Install/Uninstall application.
  • Implement and export DllRegisterServer/DllUnregisterServer functions inside your file filter.
  • Create a REG file with all required information.

The first two options give you more power because you will be able to enumerate all existing device profiles and set up your filter there as well as for future connections. The REG file will do only for future connections. Let me place it here in case you're interested:

REGEDIT4
; Register COM Object itself
[HKEY_CLASSES_ROOTCLSID{FDF0CFF3-48B4-458e-BD51-ED0C4CCBA4F1}]
@="Developer.com Sample Filter"
[HKEY_CLASSES_ROOTCLSID{FDF0CFF3-48B4-458e-BD51-ED0C4CCBA4F1}
                  DefaultIcon]
@="Dat2Log.dll,-100"
[HKEY_CLASSES_ROOTCLSID{FDF0CFF3-48B4-458e-BD51-ED0C4CCBA4F1}
                  InProcServer32]
@="Dat2Log.dll"
"ThreadingModel"="Apartment"
[HKEY_CLASSES_ROOTCLSID{FDF0CFF3-48B4-458e-BD51-ED0C4CCBA4F1}
                  PegasusFilter]
"Import"=""
"Description"="Copy DAT file with A2W conversion"
"NewExtension"="log"
"HasOptions"=""
; DAT file stuff
[HKEY_CLASSES_ROOT.dat]
@="datfile"
[HKEY_CLASSES_ROOTdatfile]
@="PC DAT File"
[HKEY_CLASSES_ROOTdatfileDefaultIcon]
@="Dat2Log.dll,-100"
; LOG file stuff
[HKEY_CLASSES_ROOT.log]
@="logfile"
[HKEY_CLASSES_ROOTlogfile]
@="PDA LOG File"
[HKEY_CLASSES_ROOTlogfileDefaultIcon]
@="Dat2Log.dll,-101"
; Register Our Filter under WinCE Services root
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows CE ServicesFilters.dat]
"DefaultImport"="{FDF0CFF3-48B4-458e-BD51-ED0C4CCBA4F1}"
"DefaultExport"="Binary Copy"
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows CE ServicesFilters
                   .datInstalledFilters]
"{FDF0CFF3-48B4-458e-BD51-ED0C4CCBA4F1}"=""

As you see, this is just regular registration stuff. Thus, you may see the results of your effort in the following figure:

Now, if you try to copy a DAT file from the desktop to the PDA, it will be converted to the selected code page.

Using the File Filter Manually

To use any file filter from your application directly, you have to recreate ActiveSync flow; for example:

  1. Implement an ICeFileFilterSite interface.
  2. Create an instance of the file filter.
  3. Fill in all structs for the source and destination files.
  4. Call ICeFileFilter::NextConvertFile.
  5. Release all stuff.

You do not need to bother implementing a full COM object for ICeFileFilterSite. Simply inherit a class from this interface and use it later on. You will find such a sample object in the accompanying zip. As a final comment, I'll give you this tiny code snippet that performs manual file conversion:

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
   int nRetCode = 0;
   // initialize MFC and print and error on failure
   if (!AfxWinInit(::GetModuleHandle(NULL), NULL,
       ::GetCommandLine(), 0))
   {
      // TODO: change error code to suit your needs
      cerr << _T("Fatal Error: MFC initialization failed") << endl;
      nRetCode = 1;
      return nRetCode;
   }
   CoInitialize(0);
   ICeFileFilter *pFilter = NULL;
   HRESULT hr = 0;
   hr = ::CoCreateInstance(CLSID_Dat2LogFileFilter,0,CLSCTX_SERVER,
                           IID_IUnknown,(void**)&pFilter);
   CCeFilterSite site;
   site.m_sSrcFile = "d:\Sample.dat";
   CFF_CONVERTINFO convertInfo;
   convertInfo.bImport = TRUE;
   convertInfo.hwndParent = NULL;
   convertInfo.bYesToAll = FALSE;
   convertInfo.pffs = &site;
   CFF_SOURCEFILE sourceFile;
   _tcscpy(sourceFile.szFullpath, _T(""));
   CFF_DESTINATIONFILE destFile;
   _tcscpy(destFile.szFullpath, _T("d:\Sample.log"));
   CF_ERROR error;
   BOOL bCancel = FALSE;
   BOOL bOK = FALSE;
   hr = pFilter->NextConvertFile(0, &convertInfo, &sourceFile,
                                 &destFile, &bCancel, &error);
   pFilter->Release();
   CoUninitialize();
   return nRetCode;
}

Conclusion

In this article, you have played around with one more MS ActiveSync supported feature. Along with the connection notifications discussed previously, it already gives you a wide elbowroom for powerful implementations. If all goes smoothly, the next articles will show you how to develop more complicated stuff, ActiveSync Service Provider components.

Download

Download the accompanying code's zip file here

About the Author

Alex Gusev started to play with mainframes at the end of the 1980s, using Pascal and REXX, but soon switched to C/C++ and Java on different platforms. When mobile PDAs seriously rose their heads in the IT market, Alex did it too. Now, he works at an international retail software company as a team leader of the Mobile R department, making programmers' lives in the mobile jungles a little bit simpler.





Page 3 of 3



Comment and Contribute

 


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

 

 


Sitemap | Contact Us

Rocket Fuel