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

📄 236-238.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=8//-->
<!--PAGES=236-238//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="234-236.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="238-242.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>The <I>RegEnumValue</I> Function
</B></FONT></P>
<P>The first registry enumeration function is <I>RegEnumValue</I>. This function is useful, for example, inside of loops where your application wants to read the data from every value in a subkey. Given the handle to an open key, an application can use this function to iterate over all values of that key, reading their data values, without knowing the names of the values being read. In fact, <I>RegEnumValue</I> reads both the value data and value name for you.</P>
<P>The syntax of <I>RegEnumValue</I> is:</P>
<!-- CODE SNIP //-->
<PRE>
  RegEnumValue(hKey, dwIndex, lpValueName,
    lpcbValueName, lpReserverd, lpType,
     lpData, lpcbData);
</PRE>
<!-- END CODE SNIP //-->
<P><I>hKey</I> is the handle of the open key whose values are being read. <I>dwIndex</I> is the index of the value to retrieve. The name of the value corresponding to <I>dwIndex</I> is returned in the <I>lpValueName</I> parameter.</P>
<P><I>lpcbValueName</I> is a pointer to a DWORD that contains the size of the <I>lpValueName</I> buffer. This parameter requires all of the caveats pointed out with the <I>lpcbData</I> parameter of <I>RegQueryValueEx</I>. Specifically, you specify the number of bytes you think the <I>lpValueName</I> string will be, and <I>RegEnumValue</I> returns the actual length through the same parameter. Hence, you need to reset this value appropriately for every <I>RegEnumValue</I> call. To further complicate matters, when you specify a value in <I>lpcbValueName</I>, you must take into account the null-terminating character of the <I>lpValueName</I> string that will be returned. But the value of <I>lpcbValueName</I> returned by <I>RegEnumValue</I> does not contain the null-terminating character.</P>
<P>The <I>lpReserved</I> parameter should again be NULL. <I>lpType</I> returns the type of data in the registry value being enumerated.</P>
<P><I>lpData</I> points to the data read from the registry value. Finally, <I>lpcbData</I> is used both to pass in the expected number of bytes to be read, and to return the actual number of bytes returned in <I>lpData</I>. The same caveats apply here as with the <I>lpcbData</I> parameter of <I>RegQueryValueEx</I>.</P>
<P>You use <I>RegEnumValue</I> by initially setting <I>dwIndex</I> to zero for the first call of the function, and then incrementing it for each successive <I>RegEnumValue</I> call. Let&#146;s extend our previous example. The code below shows how to read the number of values associated with the key HKEY_LOCAL_MACHINE\Test as before. It then iterates over all of the registry values and reads their contents:</P>
<!-- CODE //-->
<PRE>
  #define MAX_STRING_LENGTH 129
  HKEY hKeyTest;
  DWORD dwIndex;   //Loop index
  DWORD dwValueIndex; //Index of value to read
  DWORD dwValues, dwSubKeys; //Number of values, subkeys
  DWORD dwSize;     //Size of data returned by
             //<I>RegEnumValue</I>, i.e., the
             //<I>lpcbData</I> parameter
  DWORD dwSizeValue;  //Size of the value name string
             //read, i.e., the <I>RegEnumValue</I>
             //<I>lpcbValueName</I> parameter
  RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Test"),
    0, 0, &#38;hKeyText);
  if (ERROR_SUCCESS == RegQueryInfoKey(hKeyTest,NULL,
    NULL, NULL, &#38;dwSubKeys, NULL, NULL, &#38;dwValues,
     NULL, NULL, NULL, NULL))
  &#123;
    dwValueIndex = 0; //Init to zero to read first value
    for (dwIndex=0; dwIndex&lt;dwValues; dwIndex&#43;&#43;)
    &#123;
     dwSizeValue = MAX_STRING_LENGTH;
     dwSize = sizeof(DWORD);
     if (ERROR_SUCCESS==RegEnumValue(
      hKeyTest, dwKeyIndex&#43;&#43;,pszValue,
       &#38;dwSizeValue, NULL, &#38;dwType,
        (LPBYTE)&#38;dwValue, &#38;dwSize))
     &#123;
      //Do something with the data
      //read in dwValue
     &#125;
    &#125;      //End of for dwIndex loop
  &#125;        //End of if (ERROR_SUCCESS==RegQueryInfoKey)
           //statement
  RegCloseKey(hKeyTest);    //Close the key
</PRE>
<!-- END CODE //-->
<P>The first part of this example is essentially the same as in the previous example. After opening the registry key HKEY_LOCAL_MACHINE\ Test, we call <I>RegQueryInfoKey</I> to determine the number of values in the key.</P>
<P>The code then reads each of the registry values with a call to <I>RegEnumValue</I>. The for loop iterates over <I>dwValues</I>, the number of registry values as determined by the <I>RegQueryInfoKey</I> call. Notice that <I>dwValueIndex</I> is initialized to zero, and then incremented with every <I>RegEnumValue</I> call. This ensures that each registry key value is read in order.</P>
<P>Also, <I>dwSizeValue</I> and <I>dwSize</I> are reset after every <I>RegEnumValue</I> call. Recall that the <I>lpcbValueName</I> and <I>lpcbData</I> parameters of <I>RegEnumValue</I> are used by the function as return values, and, therefore, the values you initially set may be gone.</P>
<P>At the end we close the key with <I>RegCloseKey</I>:</P>
<!-- CODE SNIP //-->
<PRE>
   RegCloseKey(hKey);
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>RegCloseKey</I> function simply closes the open registry key indicated by the <I>hKey</I> parameter.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="234-236.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="238-242.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 + -