当前位置:网站首页>Read the registry through the ATL library clegkey (simple and convenient)
Read the registry through the ATL library clegkey (simple and convenient)
2022-07-24 19:34:00 【Yulong_】
Preface
It didn't work much before ATL library , Basically, you are calling the system API, Microsoft API Cumbersome and complicated and many pits , Don't read carefully MSDN Original English document , I'm afraid to use it , Especially some rare API, A search on the Internet turned out to be a large area , But few are right , ha-ha !
Text
Now the ATL The library is in use , Read and write like a file 、 The registry 、 Containers 、 Strings and so on , similar STL In the container ,ATL There are also basically , Personal feeling ATL The string class in is easier to use than the standard library , Of course, there are more pits , I don't say much nonsense , This article talks about passing ATL In the library CRegKey Class to read the registry :
Take a simple example :
#include <windows.h>
#include <atlbase.h>
int main()
{
CRegKey reg;
if (ERROR_SUCCESS == reg.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion", KEY_READ))
{
WCHAR data[100] = { 0 };
ULONG size = 99;
//size For input and output And represents sizeof(TCHAR) The number of
reg.QueryStringValue(L"SM_ConfigureProgramsName", data, &size);
printf("%S\n",data);
reg.Close();
}
system("pause");
}
Registry corresponding value :

CRegistry Of Open The first parameter of the function can be filled in the following macro , The definition is as follows , Anyone who has used the registry can understand it in seconds :
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
HKEY_PERFORMANCE_DATA
HKEY_PERFORMANCE_TEXT
HKEY_PERFORMANCE_NLSTEXT
HKEY_CURRENT_CONFIG
KEY_DYN_DATA
HKEY_CURRENT_USER_LOCAL_SETTINGS
The second parameter is the path
The third parameter is the required permission , You can mainly fill in the following values :
KEY_READ
KEY_WRITE
KEY_EXECUTE
KEY_ALL_ACCESS Open After the call is successful , The following functions are also provided to query various types of values :
Call this method to retrieve the binary data for a specified value name. | |
Call this method to retrieve the DWORD data for a specified value name. | |
Call this method to retrieve the GUID data for a specified value name. | |
Call this method to retrieve the multistring data for a specified value name. | |
Call this method to retrieve the QWORD data for a specified value name. | |
Call this method to retrieve the string data for a specified value name. | |
Call this method to retrieve the data for the specified value field of m_hKey. Earlier versions of this method are no longer supported and are marked as ATL_DEPRECATED. |
It's used here QueryStringValue, The description of this function is as follows :
Call this method to retrieve the string data for a specified value name.
LONG QueryStringValue( LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars ) throw( );
Parameters
pszValueName
Pointer to a null-terminated string containing the name of the value to query.
pszValue
Pointer to a buffer that receives the string data.
pnChars
The size, in TCHARs, of the buffer pointed to by pszValue. When the method returns, pnChars contains the size, in TCHARs, of the string retrieved, including a terminating null character.
Return Value
If the method succeeds, ERROR_SUCCESS is returned. If the method fails to read a value, it returns a nonzero error code defined in WINERROR.H. If the data referenced is not of type REG_SZ, ERROR_INVALID_DATA is returned. If the method returns ERROR_MORE_DATA, pnChars equals zero, not the required buffer size in bytes.
Put a special emphasis on , The third parameter is in,out, That is, input as buffer Size , When the function returns, it represents the length of the read string , The size here is not in bytes , But rather char or wchar_t Unit .
边栏推荐
- MySQL1
- [understanding of opportunity-48]: Guiguzi - Chapter 7 - collect information in advance, make predictions and implementation plans in advance
- On dynamic application of binary array
- About the largeheap attribute
- JS part
- MySQL1
- Equals() method of object class
- Cmake series tutorial 1- initial cmake
- Detailed explanation of ELF format (I)
- Math
猜你喜欢

Original reverse compensation and size end

Rotation matrix derivation process

Database index: index is not a panacea

strlen函数剖析和模拟实现

Hidden Markov model HMM

Common methods of string class

Sequences, time series and prediction in tessorflow quizs on coursera (II)

Sword finger offer 52. The first common node of the two linked lists

MySQL1

拿捏C指针
随机推荐
Getaverse,走向Web3的远方桥梁
原反补及大小端
聊下自己转型测试开发的历程
day 3
文献阅读:GoPose 3D Human Pose Estimation Using WiFi
How does PostgreSQL decide PG's backup strategy
Colon sorting code implementation
MySQL (data types and integrity constraints)
Day 10 (inheritance, rewriting and use of super)
Mysql database, de duplication, connection
Look at the interface control devaxpress WinForms - how to customize auxiliary function properties (Part 2)
Getaverse, a distant bridge to Web3
Sword finger offer 52. The first common node of the two linked lists
Biopharmaceutical safety, power supply and production guarantee
Pay close attention! List of the latest agenda of 2022 open atom open source Summit
Meshlab & PCL ISS key points
Recursion of function [easy to understand]
Mysql8.0 learning record 19 - Page segments and tablespaces
How to encrypt your own program with dongle
Flink window & time principle