Windows API one-day training (65) regqueryvalueex Function

Source: Internet
Author: User

The last time we introduced how to save the data to the Registry, We need to read the data from the registry. In this example, we read the string data and mainly call the regqueryvalueex function. In the following example, we first query the length of the key value and then read the content.
 
The regqueryvalueex function declaration is as follows:
 
Winadvapi
Long
Apientry
Regqueryvalueexa (
_ In hkey,
_ In_opt lpcstr lpvaluename,
_ Reserved lpdword lpreserved,
_ Out_opt lpdword lptype,
_ Out_bcount_opt (* lpcbdata) lpbyte lpdata,
_ Inout_opt lpdword lpcbdata
);
Winadvapi
Long
Apientry
Regqueryvalueexw (
_ In hkey,
_ In_opt lpcwstr lpvaluename,
_ Reserved lpdword lpreserved,
_ Out_opt lpdword lptype,
_ Out_bcount_opt (* lpcbdata) lpbyte lpdata,
_ Inout_opt lpdword lpcbdata
);
# Ifdef Unicode
# Define regqueryvalueex regqueryvalueexw
# Else
# Define regqueryvalueex regqueryvalueexa
# Endif //! Unicode
 
Hkey is the primary key.
Lpvaluename is the key value name.
Lptype is a type.
Lpdata is the place where read data is stored.
The number of data read is the number of data read.
 
An example of calling a function is as follows:
#001 // enter the Registry return value. HKEY_CURRENT_USER/"software"/"wincpp"/"testreg"
#002 // "Windows" // "winsize" = "800*600"
#003 // Cai junsheng 2007/11/05 QQ: 9073204 Shenzhen
#004 STD: wstring getprofilestring (maid, maid,
#005 lpctstr lpszdefault)
#006 {
#007 // open the application key.
#008 hkey happkey = getappregistrykey ();
#009 if (happkey = NULL)
#010 {
#011 return lpszdefault;
#012}
#013
#014 hkey hseckey = NULL;
#015 DWORD dw;
#016
#017 // open the subkey.
#018 regcreatekeyex (happkey, lpszsection, 0, reg_none,
#019 reg_option_non_volatile, key_write | key_read, null,
#020 & hseckey, & DW );
#021 regclosekey (happkey );
#022
#023 if (hseckey = NULL)
#024 {
#025 return lpszdefault;
#026}
#027
#028 // query the key value.
#029 STD: wstring strvalue;
#030 DWORD dwtype = reg_none;
#031 DWORD dwcount = 0;
#032
#033 // query the length of the key value first.
#034 long lresult = regqueryvalueex (hseckey, (lptstr) lpszentry, null, & dwtype,
#035 null, & dwcount );
#036 if (lresult = error_success)
#037 {
#038 strvalue. Resize (dwcount );
#039
#040 // query the key value.
#041 lresult = regqueryvalueex (hseckey, (lptstr) lpszentry, null, & dwtype,
#042 (lpbyte) strvalue. Data (), & dwcount );
#043
#044}
#045
#046 regclosekey (hseckey );
#047 if (lresult = error_success)
#048 {
#049 return strvalue;
#050}
#051
#052 return lpszdefault;
#053}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.