📄 415-419.html
字号:
<INPUT NAME="queryText" size=50 VALUE=""> <input type="submit" name="submitbutton" value="Go!">
<INPUT type=hidden NAME="section_on" VALUE="on">
<INPUT type=hidden NAME="section" VALUE="http://www.itknowledge.com/reference/standard/0471327476/">
</form>
<!-- Empty Reference Subhead -->
<!--ISBN=0471327476//-->
<!--TITLE=Essential Windows CE Application Programming//-->
<!--AUTHOR=Robert Burdick//-->
<!--PUBLISHER=John Wiley & Sons, Inc.//-->
<!--IMPRINT=Wiley Computer Publishing//-->
<!--CHAPTER=15//-->
<!--PAGES=415-419//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="412-415.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="419-420.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B><I>The CFF_SOURCEFILE and CFF_DESTINATIONFILE Structures</I></B></FONT></P>
<P>CFF_SOURCEFILE describes the source file being copied and filtered.
</P>
<!-- CODE //-->
<PRE>
typedef struct tagCFF_SOURCEFILE
{
TCHAR szFullpath[_MAX_PATH];
TCHAR szPath[_MAX_PATH];
TCHAR szFilename[_MAX_FNAME];
TCHAR szExtension[_MAX_EXT];
DWORD cbSize;
FILETIME ftCreated;
FILETIME ftModified;
} CFF_SOURCEFILE;
</PRE>
<!-- END CODE //-->
<P>These members are all pretty self-explanatory. <I>szFullPath</I> is the fully qualified path name of the file, including the file name. <I>szPath</I> is the directory name part of <I>szFullPath</I>. <I>cbSize</I> is the size of the source file in bytes. <I>ftCreated</I> and <I>ftModified</I> are the creation and last-modified times of the file, respectively.</P>
<P>The CFF_DESTINATIONFILE structure is very similar. It contains the first four members of the CFF_SOURCEFILE structure.</P>
<!-- CODE SNIP //-->
<PRE>
typedef struct tagCFF_DESTINATIONFILE
{
TCHAR szFullpath[_MAX_PATH];
TCHAR szPath[_MAX_PATH];
TCHAR szFilename[_MAX_FNAME];
TCHAR szExtension[_MAX_EXT];
} CFF_DESTINATIONFILE
</PRE>
<!-- END CODE SNIP //-->
<P><FONT SIZE="+1"><B>An Example</B></FONT></P>
<P>To make this all more clear, let’s look at an example. The <I>NextConvertFile</I> implementation from the sample filter FILTER.DLL looks like this:</P>
<!-- CODE //-->
<PRE>
STDMETHODIMP CImportFilter::NextConvertFile(
int nConversion,
CFF_CONVERTINFO* pci,
CFF_SOURCEFILE* psf,
CFF_DESTINATIONFILE* pdf,
volatile BOOL *pbCancel,
CF_ERROR *perr)
{
ICeFileFilterSite* pffs; //Pointer to input file filter
//site interface
IStream *pSrcFile, *pDstFile;
PF_ERROR pfError;
HRESULT hResult, hResClose;
if (nConversion)
{
return (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS));
}
pffs = pci->pffs;
//Open the source file for reading
hResult = pffs->OpenSourceFile(PF_OPENFLAT,
(LPVOID*)&pSrcFile);
if (!SUCCEEDED(hResult))
{
pfError = HRESULT_TO_PFERROR(hResult,
ERROR_ACCESS_DENIED);
}
else //Open the desination file for writing
{
hResult = pffs->OpenDestinationFile(
PF_OPENFLAT,
NULL,
(LPVOID*)&pDstFile);
if (!SUCCEEDED(hResult))
{
pfError = HRESULT_TO_PFERROR(hResult,
ERROR_ACCESS_DENIED);
}
else
{
hResult = _NextConvertFile(pSrcFile, pDstFile, pffs,
psf, pbCancel, perr);
hResClose =
pffs->CloseDestinationFile(SUCCEEDED(hResult),
pDstFile);
if (SUCCEEDED(hResult))
{
pfError = HRESULT_TO_PFERROR(hResult,
ERROR_ACCESS_DENIED);
hResult = hResClose;
}
}
} //End of else open destination file block
pffs->CloseSourceFile(pSrcFile);
*perr = pfError;
return (hResult);
}
</PRE>
<!-- END CODE //-->
<P>The first thing this<I></I> function does is check the value of the <I>nConversion</I> parameter. If this value is not zero, it returns the HRESULT value, which tells Windows CE Services to stop calling the function.</P>
<P>Next, the source and destination files are opened. If either file open operation fails, an appropriate error code is returned. Otherwise the <I>_NextConvertFile</I> method is called. This method simply reads the source file data and writes it to the destination file. It is a pretty straightforward function that uses the Win32 file system API. Since we are mainly concentrating on the high-level design of Windows CE file filters, we do not discuss <I>_NextConvertFile</I> here.</P>
<P>Finally, files are closed with the <I>CloseDestinationFile</I> and <I>CloseSourceFile</I> calls.</P>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Registering File Filters</FONT></H3>
<P>Like ActiveSync service providers, Window CE file filters must be properly registered before they can be used. Since file filters are only implemented on the desktop, they require no device registry entries.
</P>
<P>Like any COM object, file filters are registered under their class identifier. The following registry entries must be made under the filter’s CLSID:</P>
<!-- CODE //-->
<PRE>
[HKEY_CLASSES_ROOT\CLSID\{11732CC1-65D8-11d2-9BF2-000000000000}]
@="Windows CE Import File Filter Sample"
[HKEY_CLASSES_ROOT\CLSID\{11732CC1-65D8-11d2-9BF2-000000000000}\InProc-
Server32]
@="e:\\Samples\\filter\\Release\\filter.dll"
"ThreadingModel"="Apartment"
[HKEY_CLASSES_ROOT\CLSID\{11732CC1-65D8-11d2-9BF2-000000000000}\Pegasus-
Filter]
"Import"=""
"Description"="FILTER File"
"NewExtension"="pft"
[HKEY_CLASSES_ROOT\CLSID\{11732CC1-65D8-11d2-9BF2-000000000000}\Default-
Icon]
@="e:\\Samples\\filter\\release\\filter.dll,-101"
</PRE>
<!-- END CODE //-->
<P>These are the usual registry key settings for a COM object, except for the PegasusFilter and DefaultIcon keys.
</P>
<P>PegasusFilter contains three named values. Import tells Windows CE Services that the filter is for importing files from a desktop computer to a Windows CE device. If instead the named value Export was used, the filter is an export file filter. Description contains a file type description string. NewExtension specifies the file extension to be assigned to a file after it is transferred with this filter.</P>
<P>The DefaultIcon subkey specifies the icon to use with the file filter. This icon appears, for example, in the File Conversion dialog box property sheets describing the filter.</P>
<P>A file filter must also be registered under the appropriate Windows CE Services subkeys. For example, the import filter for converting .flt files to .pft files includes these registry settings:</P>
<!-- CODE SNIP //-->
<PRE>
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows CE
Services\Partners\<Partner ID>\Filters\.flt\InstalledFilters]
"{11732CC1-65D8-11d2-9BF2-000000000000}"=""
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows CE
Services\Partners\<Partner ID>\Filters\.flt]
"DefaultImport"="{11732CC1-65D8-11d2-9BF2-000000000000}"
</PRE>
<!-- END CODE SNIP //-->
<P>The InstalledFilters subkey lists the class identifiers of all filters that can convert the corresponding file type. The DefaultImport value under the .flt subkey identifies which filter is to be used by default.
</P>
<P>Finally, to complete the registration of our .flt file filter, these registry entries are required:</P>
<!-- CODE SNIP //-->
<PRE>
[HKEY_CLASSES_ROOT\.flt]
@="fltfile"
[HKEY_CLASSES_ROOT\fltfile]
@="FILTER: Desktop FLT File"
[HKEY_CLASSES_ROOT\fltfile\DefaultIcon]
@="e:\\Samples\\filter\\release\\filter.dll,-101"
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="412-415.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="419-420.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<!-- all of the reference materials (books) have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- BEGIN SUB FOOTER -->
<br><br>
</TD>
</TR>
</TABLE>
<table width="640" border=0 cellpadding=0 cellspacing=0>
<tr>
<td align="left" width=135><img src="/images/white.gif" width=100 height="1" alt="" border="0"></td>
<!-- END SUB FOOTER -->
<!-- all of the books have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- FOOTER -->
<td width="515" align="left" bgcolor="#FFFFFF">
<font face="arial, helvetica" size="1"><b><a href="/products.html"><font color="#006666">Products</font></a> | <a href="/contactus.html"><font color="#006666">Contact Us</font></a> | <a href="/aboutus.html"><font color="#006666">About Us</font></a> | <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> | <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> | <a href="/"><font color="#006666">Home</font></a></b>
<br><br>
Use of this site is subject to certain <a href="/agreement.html">Terms & Conditions</a>, <a href="/copyright.html">Copyright © 1996-1999 EarthWeb Inc.</a><br>
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.</font><p>
</td>
</tr>
</table>
</BODY>
</HTML>
<!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -