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

📄 204-207.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
		
<!-- PUB PARTNERS END -->
<!-- END LEFT NAV -->

<td rowspan="8" align="right" valign="top"><img src="/images/iswbls.gif" width=1 height=400 alt="" border="0"></td>
<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=7//-->
<!--PAGES=204-207//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="201-204.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="207-209.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The first argument of the <I>CeWriteRecordProps</I> function is the handle of the open database to be written to. The second argument is of type CEOID and can contain the object identifier of an existing record to be written over, or zero to indicate that a new record with the given properties is to be added to the database. A database record can thus be modified by calling <I>CeWriteRecordProps</I> and passing the object identifier of this record in the second parameter. The third parameter indicates the number of properties contained in the fourth parameter, which is the array of CEPROPVALs containing the data to be written to the database. <I>CeWriteRecordProps</I> returns the object identifier of the record that was written.</P>
<P>The <I>wFlags</I> member of any of the CEPROPVAL structures can either be zero or CEDB_PROPDELETE. If CEDB_PROPDELETE, the write operation deletes the property from the record. In this way <I>CeWriteRecordProps</I> can remove selected properties from existing database records.</P>
<P>Reading a record from the database requires <I>CeReadRecordProps</I>. This function reads and returns the record as one big block of bytes that actually contains a set of CEPROPVAL structures, one per record property. Once the record data is read, it is the responsibility of your application to unpack the data array, breaking it down into the constituent properties.</P>
<P>The <I>CeReadRecordProps</I> function has the following definition:</P>
<!-- CODE SNIP //-->
<PRE>
   CeReadRecordProps(hDBase, dwFlags, lpcPropID, rgPropID,
     lplpBuffer, lpcbBuffer);
</PRE>
<!-- END CODE SNIP //-->
<P>The first argument is the handle to the open database. <I>dwFlags</I> can either be zero or CEDB_ALLOWREALLOC. Applications will usually use this value, indicating that <I>CeReadRecordProps</I> has permission to reallocate the data buffer <I>lplpBuffer</I> if it doesn&#146;t contain enough space to hold all of the record data. <I>lpcPropID</I> is an LPWORD indicating the number of properties to be retrieved. <I>rgPropID</I> is an array of CEPROPID values that tells the function which record properties to read.</P>
<P><I>CeReadRecordProps</I> can thus be used to read any or all of the properties in a given database record. To read all properties, set <I>lpcPropID</I> to zero and <I>rgPropID</I> to NULL. If these two parameters are used in this way, <I>lpcPropID</I> contains the number of properties read once the function returns.</P>
<P>After the function executes, <I>lplpBuffer</I> contains the record property data and <I>lpcbBuffer</I> contains the total number of bytes in the buffer. If <I>CeReadRecordProps</I> succeeds, it return the object identifier of the record that was read. If it fails, it will return zero, in which case you can call <I>GetLastError</I> to get more detailed information about what went wrong.</P>
<P>It is possible that a property specified in the <I>rgPropID</I> array does not exist in the record retrieved by <I>CeReadRecordProps</I>. For example, an application might accidentally specify an invalid property identifier, or specify a property that has been previously deleted from the record. In these cases, the <I>wFlags</I> parameter of the CEPROPVAL structure extracted from <I>lplpBuffer</I> for that property will be set to CEDB_PROPNOTFOUND.</P>
<P>At this point, all that is left to do is to convert the data array returned by <I>CeReadRecordProps</I> into the property data. Since <I>lpcPropID</I> contains the number of properties contained by the record data buffer, the simplest way to do this is to cast the data buffer into an array of CEPROPVAL structures and iterate on each property as follows:</P>
<!-- CODE //-->
<PRE>
   WORD cProps = 0;
   LPBYTE pBuf=NULL;
   DWORD cbByte = 0;
   PCEPROPVAL pVals;
   CEOID oid;
   int i;
   //hDBase is a handle to the (previously opened) database
   oid = CeReadRecordProps(hDBase, CEDB_ALLOWREALLOC, &#38;cProps,
     NULL, &#38;pBuf, &#38;cbByte);
   //Unpack all of the record properties
   pVals = (PCEPROPVAL)pBuf;
   for (i=0; i&lt;cProps; i&#43;&#43;)
   &#123;
     switch(HIWORD(pVals[i].propid))
     &#123;
      case PL_LASTNAME_INDEX:
      /* pVals[i].val.lpwstr contains the last name property
        value: The application needs to do something with it.
       */
       break;
      case PL_FIRSTNAME_INDEX:
      /* pVals[i].val.lpwstr contains the first name property */
       break;
      case PL_PHONENUMBER_INDEX:
      /* pVals[i].val.lpwstr contains the phone number
       property
       */
       break;
      case PL_DEPT_INDEX:
      /* pVals[i].val.iVal contains the dept number property */
       break;
      default:
       break;
     &#125;          //End of switch statement*
   &#125;            //End of for (i=0; i&lt;cProps; i&#43;&#43;) loop
   LocalFree(pBuf);
</PRE>
<!-- END CODE //-->
<P>The LPBYTE array of raw record data is cast to an array of CEPROPVAL structures (the <I>pVals</I> variable). The for loop that follows then executes once for each property that was read from the current record by the <I>CeReadRecordProps</I> call. The switch statement checks the application-defined index of the current property in the <I>pVals</I> array, and extracts the value of that record accordingly (recall that the high word of each <I>propid</I> member of a CEPROPVAL contains the application-defined index of a particular property). The <I>val</I> members of the individual CEPROPVALs can be assigned to other variables as needed, or, as we will show later, used to construct a database record structure that is used by the application to more clearly represent the data. Notice that we free (using <I>LocalFree</I>) the data buffer returned by <I>CeReadRecordProps</I> after using it. This needs to be done whether or not the read operation was successful, as <I>CeReadRecordProps</I> might allocate memory in any attempt to read a database record.</P>
<P><FONT SIZE="+1"><B>Deleting Database Records</B></FONT></P>
<P>Finally, we need to describe how to delete database records. Deleting records from a Windows CE database is done with the <I>CeDeleteRecord</I> function:</P>
<!-- CODE SNIP //-->
<PRE>
   CeDeleteRecord(hDatabase, oidRecord);
</PRE>
<!-- END CODE SNIP //-->
<P><I>hDatabase</I> is the handle of the open database from which the record is to be removed. <I>oidRecord</I> is the CEOID identifying the record to delete.</P>
<P><I>CeDeleteRecord</I> returns TRUE if the specified record is successfully deleted from the database. Otherwise the function returns FALSE. In this case, an application can call <I>GetLastError</I> for more information about why the delete operation failed.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="201-204.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="207-209.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 + -