⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 165-168.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<td><img src="/images/white.gif" width="5" height="1" alt="" border="0"></td>
<!-- end of ITK left NAV -->

<!-- begin main content -->
<td width="100%" valign="top" align="left">


<!-- END SUB HEADER -->

<!--Begin Content Column -->

<FONT FACE="Arial,Helvetica" SIZE="-1">
To access the contents, click the chapter and section titles.
</FONT>
<P>
<B>Essential Windows CE Application Programming</B>
<FONT SIZE="-1">
<BR>
<I>(Publisher: John Wiley & Sons, Inc.)</I>
<BR>
Author(s): Robert Burdick
<BR>
ISBN: 0471327476
<BR>
Publication Date: 03/01/99
</FONT>
<P>
<form name="Search" method="GET" action="http://search.earthweb.com/search97/search_redir.cgi">

<INPUT TYPE="hidden" NAME="Action" VALUE="Search">
<INPUT TYPE="hidden" NAME="SearchPage" VALUE="http://search.earthweb.com/search97/samples/forms/srchdemo.htm">
<INPUT TYPE="hidden" NAME="Collection" VALUE="ITK">
<INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="itk-simple-intrabook.hts">
<INPUT TYPE="hidden" NAME="ViewTemplate" VALUE="view.hts">

<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="queryText" size=50 VALUE="">&nbsp;<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=6//-->
<!--PAGES=165-168//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="162-165.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="168-171.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading9"></A><FONT COLOR="#000077">Creating and Opening Files and Directories</FONT></H3>
<P>As under Windows NT, creating files and directories under Windows CE is done using the <I>CreateFile</I> and <I>CreateDirectory</I> functions. Under Windows CE, files are also opened using the <I>CreateFile</I> function, as we will soon see.</P>
<P><FONT SIZE="+1"><B>Creating and Opening Files</B></FONT></P>
<P>To create a file, your application calls the <I>CreateFile</I> function:</P>
<!-- CODE SNIP //-->
<PRE>
  CreateFile(lpFileName,dwDesiredAccess,dwShareMode,
    lpSecurityAttributes, dwCreationDistribution,
     dwFlagsAndAttributes, hTemplateFile);
</PRE>
<!-- END CODE SNIP //-->
<P><I>lpFileName</I> is the null-terminated Unicode string file name of the file to be created. Long file names are supported.</P>
<P><I>dwDesiredAccess</I> is used to indicate the access, or read-write mode, of the file. It can be any combination of the following values:</P>
<DL>
<DD><B>0.</B> Specifies device query access. This allows an application to query device attributes.
<DD><B>GENERIC_READ.</B> Specifies that the file is created/opened with read access.
<DD><B>GENERIC_WRITE.</B> Specifies that the file is created/opened with write access.
</DL>
<P>For example, to open a file called &#147;myfile.txt&#148; with read-write access, an application would do the following:
</P>
<!-- CODE SNIP //-->
<PRE>
  CreateFile(TEXT("myfile.txt"),
  (GENERIC_READ|GENERIC_WRITE),...);
</PRE>
<!-- END CODE SNIP //-->
<P>The third parameter to <I>CreateFile</I>, <I>dwShareMode</I>, is used to specify if and how the file can be shared. It can be a combination of one or more of the following values:</P>
<DL>
<DD><B>0.</B> Indicates that the file cannot be shared
<DD><B>FILE_SHARED_READ.</B> Subsequent open operations on the file will only succeed if read access is requested (via the <I>dwDesiredAccess</I> parameter).
<DD><B>FILE_SHARED_WRITE.</B> Subsequent open operations on the file will only succeed if write access is requested.
</DL>
<P>Under Windows CE, file security attributes are ignored. The <I>lpSecurityAttributes</I> parameter should therefore be set to NULL.</P>
<P>The <I>dwCreationDistribution</I> parameter controls how the <I>CreateFile</I> function behaves when attempting to create existing files, as well as what to do when the function tries to open a nonexistent file. This parameter can be one of the following:</P>
<DL>
<DD><B>CREATE_NEW.</B> The function creates a new file. If the specified file already exists, the <I>CreateFile</I> function fails.
<DD><B>CREATE_ALWAYS.</B> The function creates a new file. If the specified file already exists, it is overwritten by the <I>CreateFile</I> operation.
<DD><B>OPEN_EXISTING.</B> The function opens an existing file. If the specified file does not exist, <I>CreateFile</I> fails.
<DD><B>OPEN_ALWAYS.</B> The function opens an existing file. If the specified file does not already exist, it is created.
<DD><B>TRUNCATE_EXISTING.</B> The function opens the file, but truncates it to zero length. The file must be opened with GENERIC_WRITE access. <I>CreateFile</I> fails if the specified file does not exist.
</DL>
<P>By taking a look at the allowed <I>dwCreationDistribution</I> values, we can see how <I>CreateFile</I> can be used to both create new files and open existing files. For example, it is common to want to open a file or have the operating system create a file of that name if it does not exist, as follows:</P>
<!-- CODE SNIP //-->
<PRE>
  CreateFile(TEXT("myfile.txt"),
  GENERIC_READ|GENERIC_WRITE, 0,
    NULL, OPEN_ALWAYS,...);
</PRE>
<!-- END CODE SNIP //-->
<P><I>dwFlagsAndAttributes</I> determines the file attributes and several operating modes. We have already discussed file attributes. The flags portion can be any combination of the following values:</P>
<DL>
<DD><B>FILE_FLAG_WRITE_THROUGH.</B> Instructs Windows CE to write directly to the object store when writing to the specified file, as opposed to writing through any intermediate cache.
<DD><B>FILE_FLAG_RANDOM_ACCESS.</B> The file supports random access.
</DL>
<P>Most of the flags that are supported under Windows NT are not supported under Windows CE. Also note that the SECURITY_SQOS_ PRESENT flag, or any of the other values that can be used with it under Windows NT, are not supported under Windows CE.
</P>
<P>Finally, the <I>hTemplateFile</I> parameter is ignored under Windows CE and should be set to NULL.</P>
<P>If <I>CreateFile</I> is successful, a handle to the open file is returned. If it fails, the return value is INVALID_HANDLE_VALUE.</P>
<P>Open files are closed using the <I>CloseHandle</I> function:</P>
<!-- CODE SNIP //-->
<PRE>
  CloseHandle(hObject);
</PRE>
<!-- END CODE SNIP //-->
<P>where <I>hObject</I> is the handle of the file to close.</P>
<P><FONT SIZE="+1"><B>Creating Directories</B></FONT></P>
<P>Creating a directory is accomplished with the <I>CreateDirectory</I> function. The <I>CreateDirectoryEx</I> function available under Windows NT is not supported in Windows CE. The <I>CreateDirectory</I> function syntax is:</P>
<!-- CODE SNIP //-->
<PRE>
  CreateDirectory(lpPathName, lpSecurityAttributes);
</PRE>
<!-- END CODE SNIP //-->
<P><I>lpPathName</I> is a null-terminated Unicode string specifying the path of the directory to be created. The maximum allowed length of this name is the operating system&#150;defined value MAX_PATH. The second parameter to this function is ignored, as Windows CE does not support file security attributes. <I>lpSecurityAttributes</I> therefore should be set to NULL.</P>
<P>If <I>CreateDirectory</I> is successful, it returns TRUE. If unsuccessful, it returns FALSE. An application can get more detailed information about why the function failed by calling <I>GetLastError</I>.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="162-165.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="168-171.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>&nbsp;|&nbsp; <a href="/contactus.html"><font color="#006666">Contact Us</font></a>&nbsp;|&nbsp; <a href="/aboutus.html"><font color="#006666">About Us</font></a>&nbsp;|&nbsp; <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> &nbsp;|&nbsp; <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> &nbsp;|&nbsp; <a href="/"><font color="#006666">Home</font></a></b>
		<br><br>
		
		Use of this site is subject to certain <a href="/agreement.html">Terms &amp; Conditions</a>, <a href="/copyright.html">Copyright &copy; 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 + -