浅蓝色的琴弦
微风祈愿

//建立注册字段
This function creates the specified key. If the key already exists in the registry, the function opens it.

A remote application interface (RAPI) version of this function exists, and it is called CeRegCreateKeyEx (RAPI).

LONG RegCreateKeyEx( 
HKEY hKey, 
LPCWSTR lpSubKey, 
DWORD Reserved, 
LPWSTR lpClass, 
DWORD dwOptions, 
REGSAM samDesired, 
LPSECURITY_ATTRIBUTES lpSecurityAttributes, 
PHKEY phkResult, 
LPDWORD lpdwDisposition 
); 

Parameters

hKey
[in] Handle to a currently open key or one of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS

Windows CE does not support the HKEY_CURRENT_CONFIG, HKEY_PERFORMANCE_DATA, or HKEY_DYN_DATA predefined reserved handle values.

The key opened or created by the RegCreateKeyEx function is a subkey of the key identified by the hKey parameter.

lpSubKey
[in] Pointer to a null-terminated string specifying the name of a subkey that this function opens or creates. The subkey specified must be a subkey of the key identified by the hKey parameter. This subkey must not begin with the backslash character (\). If the parameter is NULL, then RegCreateKeyEx behaves like RegOpenKey where it opens the key specified by hKey. In Windows CE, the maximum length of a key name is 255 characters, not including the terminating NULL character. You can also only nest 16 levels of sub-keys in Windows CE.
Reserved
[in] Reserved; set to 0.
lpClass
[in] Pointer to a null-terminated string that specifies the class (object type) of this key. This parameter is ignored if the key already exists. In Windows CE, the maximum length of a class string is 255 characters, not including the terminating NULL character.
dwOptions
[in] Registry key options. The following table shows the possible values for this parameter.
Value Description
REG_OPTION_NON_VOLATILE Default setting. All registry keys are created as non-volatile and the information stored in memory is preserved when the OS is restarted. The RegSaveKey function saves keys that are non-volatile.
REG_OPTION_VOLATILE All registry keys are created as volatile, and the information is stored in memory and is not preserved when the corresponding registry hive is unloaded. For HKEY_LOCAL_MACHINE, this occurs when the OS is shut down. The RegSaveKey function does not save volatile registry keys. This flag is ignored for keys that already exist.
samDesired
[in] Ignored; set to 0 to ensure compatibility with future versions of Windows CE.
lpSecurityAttributes
[in] Set to NULL. Windows CE automatically assigns the key a default security descriptor.
phkResult
[out] Pointer to a variable that receives a handle to the opened or created key. When you no longer need the returned handle, call the RegCloseKey function to close it.
lpdwDisposition
[out] Pointer to a variable that receives disposition values. The following table shows possible values for this parameter.
Value Description
REG_CREATED_NEW_KEY The key did not exist and was created.
REG_OPENED_EXISTING_KEY The key existed and was simply opened without being changed.

Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you call FormatMessage it could fail.

Remarks

The key that the RegCreateKeyEx function creates has no values. An application can use the RegSetValueEx function to set key values.

An application can use RegCreateKeyEx to temporarily lock a portion of the registry. When the locking process creates a new key, it receives the disposition value REG_CREATED_NEW_KEY, indicating that it owns the lock. Another process attempting to create the same key receives the disposition value REG_OPENED_EXISTING_KEY, indicating that another process already owns the lock.

//开打注册表字段

This function opens the specified key.

A remote application interface (RAPI) version of this function exists, and it is called CeRegOpenKeyEx (RAPI).

LONG RegOpenKeyEx( 
HKEY hKey, 
LPCWSTR lpSubKey, 
DWORD ulOptions, 
REGSAM samDesired, 
PHKEY phkResult 
); 

Parameters

hKey
[in] Handle to a currently open key or any of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS

Windows CE does not support the HKEY_CURRENT_CONFIG, HKEY_PERFORMANCE_DATA, or HKEY_DYN_DATA predefined reserved handle values.

lpSubKey
[in] Pointer to a null-terminated string containing the name of the subkey to open. If this parameter is NULL or a pointer to an empty string, the function will open a new handle to the key identified by the hKey parameter. In this case, the function will not close the handles previously opened.
ulOptions
[in] Reserved; set to 0.
samDesired
[in] Not supported; set to 0.
phkResult
[out] Pointer to a variable that receives a handle to the opened key. When you no longer need the returned handle, call the RegCloseKey function to close it.

Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you call FormatMessage it could fail.

Remarks

Unlike the RegCreateKeyEx function, the RegOpenKeyEx function does not create the specified key if the key does not exist in the registry.


//写入字段值

This function stores data in the value field of an open registry key. It can also set additional value and type information for the specified key.

A remote application interface (RAPI) version of this function exists, and it is called CeRegSetValueEx (RAPI).

LONG RegSetValueEx( 
HKEY hKey, 
LPCWSTR lpValueName, 
DWORD Reserved, 
DWORD dwType, 
const BYTE* lpData, 
DWORD cbData 
); 

Parameters

hKey
[in] Handle to a currently open key or any of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS
lpValueName
[in] Pointer to a string containing the name of the value to set. If a value with this name is not already present in the key, the function adds it to the key. If this parameter is NULL or an empty string, the function sets the type and data for the key's unnamed value. Registry keys do not have default values, but they can have one unnamed value, which can be of any type. The maximum length of a value name is 255, not including the terminating NULL character.
Reserved
[in] Reserved; must be zero.
dwType
[in] Type of information to be stored as the value's data. The following table shows the possible values for dwType.
Value Description
REG_BINARY Specifies binary data in any form.
REG_DWORD Specifies a 32-bit number.
REG_DWORD_LITTLE_ENDIAN Specifies a 32-bit number in little-endian format. This is equivalent to REG_DWORD.

In little-endian format, a multi-byte value is stored in memory from the lowest byte (the little end) to the highest byte. For example, the value 0x12345678 is stored as (0x78 0x56 0x34 0x12) in little-endian format.

REG_DWORD_BIG_ENDIAN Specifies a 32-bit number in big-endian format.

In big-endian format, a multi-byte value is stored in memory from the highest byte (the big end) to the lowest byte. For example, the value 0x12345678 is stored as (0x12 0x34 0x56 0x78) in big-endian format.

REG_EXPAND_SZ Specifies a null-terminated string that contains unexpanded references to environment variables (for example, %PATH%).
REG_LINK Specifies a Unicode symbolic link. Used internally; applications should not use this type.
REG_MULTI_SZ Specifies an array of null-terminated strings, terminated by two null characters.
REG_NONE No defined value type.
REG_RESOURCE_LIST Specifies a device-driver resource list.
REG_SZ Specifies a null-terminated Unicode string. Do not use the REG_SZ type to store hard-coded paths to the system root.
lpData
[in] Pointer to a buffer containing the data to be stored with the specified value name.
cbData
[in] Size, in bytes, of the information pointed to by the lpData parameter. If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must include the size of the terminating null character. The maximum size of data allowed in Windows CE is 4 KB.

Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you call FormatMessage it could fail.

Remarks

Value lengths are limited by available memory. Long values (more than 2048 bytes) should be stored as files with the filenames stored in the registry. This helps the registry perform efficiently. Application elements such as icons, bitmaps, and executable files should be stored as files and not be placed in the registry.

Windows CE supports only the Unicode version of this function.

Windows Mobile Remarks

If RegSetValueEx is used to change a value, but the new value is the same as the previous value, no notification is returned.


//保存字段值

This function saves the specified key and all of its subkeys and values to a new file. If the specified key is not a predefined ROOT, it backs up to the ROOT of the hKey and saves there.

LONG RegSaveKey(
HKEY hKey,
LPCTSTR lpFile,
LPSECURITY_ATTRIBUTES lpSecurityAttributes
);

Parameters

hKey
[in] Specifies a handle to the key where the save operation is to begin, or any of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS
lpFile
[in] Pointer to a null-terminated string containing the name of the file in which the specified key and subkeys are saved.
lpSecurityAttributes
[in] Must be NULL.

Return Values

If the function succeeds, the return value is ERROR_SUCCESS.

The function may fail with GetLastError returning ERROR_NOT_SUPPORTED because it is not supported on the object store-based registry.

If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Remarks

The RegSaveKey API is only supported by the hive-based registry. To save and restore data in the object store-based registry, see RegCopyFile and RegRestoreFile.

While you can call RegSaveKey with any registry key, in effect it only provides two choices. If it is called with HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_USERS, or any key under those roots, it saves a copy of the entire system hive, which includes all keys under these roots. If it is called with HKEY_CURRENT_USER or any key under it, it saves a copy of the entire user hive, which includes all keys under HKEY_CURRENT_USER.

You can use the file created by RegSaveKey in subsequent calls to RegReplaceKey with HKEY_LOCAL_MACHINE to restore the system registry hive. To restore a saved user hive, move the file into the user's profile directory while the user is not logged in. Subsequent calls to SetCurrentUser will use the restored hive.


//读取键值

This function retrieves the type and data for a specified value name associated with an open registry key.

A remote application interface (RAPI) version of this function exists, and it is called CeRegQueryValueEx (RAPI).

LONG RegQueryValueEx( 
HKEY hKey, 
LPCWSTR lpValueName, 
LPDWORD lpReserved, 
LPDWORD lpType, 
LPBYTE lpData, 
LPDWORD lpcbData 
); 

Parameters

hKey
[in] Handle to a currently open key or any of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS
lpValueName
[in] Pointer to a string containing the name of the value to query. If this parameter is NULL or an empty string, the function retrieves the type and data for the key's unnamed value. A registry key does not automatically have an unnamed or default value. Unnamed values can be of any type.
lpReserved
[in] Reserved; set to NULL.
lpType
[out] Pointer to a variable that receives the type of data associated with the specified value. The following table shows the possible values that lpType can return.
Value Description
REG_BINARY Specifies a binary data in any form.
REG_DWORD Specifies a 32-bit number.
REG_DWORD_LITTLE_ENDIAN Specifies a 32-bit number in little-endian format. This is equivalent to REG_DWORD.

In little-endian format, a multi-byte value is stored in memory from the lowest byte (the little end) to the highest byte. For example, the value 0x12345678 is stored as (0x78 0x56 0x34 0x12) in little-endian format.

REG_DWORD_BIG_ENDIAN Specifies a 32-bit number in big-endian format.

In big-endian format, a multi-byte value is stored in memory from the highest byte (the big end) to the lowest byte. For example, the value 0x12345678 is stored as (0x12 0x34 0x56 0x78) in big-endian format.

REG_EXPAND_SZ Specifies a null-terminated string that contains unexpanded references to environment variables. For example, %PATH%.
REG_LINK Specifies a Unicode symbolic link. Used internally; applications should not use this type.
REG_MULTI_SZ Specifies an array of null-terminated strings, terminated by two null characters.
REG_NONE No defined value type.
REG_RESOURCE_LIST Specifies a device-driver resource list.
REG_SZ Specifies a null-terminated Unicode string.

The lpType parameter can be NULL if the type is not required.

lpData
[out] Pointer to a buffer that receives the value's data. This parameter can be NULL if the data is not required.
lpcbData
[in, out] Pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the lpData parameter. When the function returns, this variable contains the size of the data copied to lpData.

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, then lpcbData will also include the size of the terminating null character.

The lpcbData parameter can be NULL only if lpData is NULL.

If the buffer specified by lpData parameter is not large enough to hold the data, the function returns the value ERROR_MORE_DATA, and stores the required buffer size, in bytes, into the variable pointed to by lpcbData.

If lpData is NULL, and lpcbData is non-NULL, the function returns ERROR_SUCCESS, and stores the size of the data, in bytes, in the variable pointed to by lpcbData. This lets an application determine the best way to allocate a buffer for the value's data.

Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you call FormatMessage it could fail.

Requirements

OS Versions: Windows CE 1.0 and later.
Header: Winreg.h.
Link Library: Coredll.lib.


//获取字段信息

This function retrieves information about a specified registry key.

A remote application interface (RAPI) version of this function exists, and it is called CeRegQueryInfoKey (RAPI).

LONG RegQueryInfoKey( 
HKEY hKey, 
LPWSTR lpClass, 
LPDWORD lpcbClass, 
LPDWORD lpReserved, 
LPDWORDlpcSubKeys, 
LPDWORD lpcbMaxSubKeyLen, 
LPDWORD lpcbMaxClassLen, 
LPDWORD lpcValues, 
LPDWORD lpcbMaxValueNameLen, 
LPDWORD lpcbMaxValueLen, 
LPDWORD lpcbSecurityDescriptor, 
PFILETIME lpftLastWriteTime 
); 

Parameters

hKey
[in] Handle to a currently open key or any of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS
lpClass
[out] Pointer to a buffer that receives the key's class name. This parameter can be NULL.
lpcbClass
[in, out] Pointer to a variable that specifies the size, in characters, of the buffer pointed to by the lpClass parameter. This size should include the terminating null character. When the function returns, this variable contains the length of the class string stored in the buffer. The count returned does not include the terminating null character. If the buffer is not big enough, the function returns ERROR_MORE_DATA, and the variable contains the size of the string, in characters, without counting the null character.

If lpClass is NULL, lpcbClass can be NULL.

If the lpClass parameter is a valid address, but this parameter is not, the function returns ERROR_INVALID_PARAMETER.

lpReserved
[in] Reserved; set to NULL.
lpcSubKeys
[out] Pointer to a variable that receives the number of subkeys contained by the specified key. This parameter can be NULL.
lpcbMaxSubKeyLen
[out] Pointer to a variable that receives the length, in characters, of the key's subkey with the longest name. The count returned does not include the terminating null character. This parameter can be NULL.
lpcbMaxClassLen
[out] Pointer to a variable that receives the length, in characters, of the longest string specifying a subkey class. The count returned does not include the terminating null character. This parameter can be NULL.
lpcValues
[out] Pointer to a variable that receives the number of values associated with the key. This parameter can be NULL.
lpcbMaxValueNameLen
[out] Pointer to a variable that receives the length, in characters, of the key's longest value name. The count returned does not include the terminating null character. This parameter can be NULL.
lpcbMaxValueLen
[out] Pointer to a variable that receives the length, in bytes, of the longest data component among the values of the key. This parameter can be NULL.
lpcbSecurityDescriptor
[in] Not used; set to NULL.
lpftLastWriteTime
[in] Ignored; set to NULL.

Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you call FormatMessage it could fail.

//安全关闭注册表句柄

This function releases the handle of the specified key.

A remote application interface (RAPI) version of this function exists, and it is called CeRegCloseKey (RAPI).

LONG RegCloseKey( 
HKEY hKey 
); 

Parameters

hKey
[in] Handle to the open key to close.

Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you call FormatMessage it could fail.

Remarks

The handle for a specified key should not be used after it has been closed, because it will no longer be valid. Key handles should not be left open any longer than necessary.

The RegCloseKey function always writes information to the registry before returning, eliminating the need to flush keys in the Windows CE registry.


删除键值

This function recursively deletes all subkeys of a named subkey of a specified registry key.

A remote application interface (RAPI) version of this function exists, and it is called CeRegDeleteKey (RAPI).

LONG RegDeleteKey( 
HKEY hKey, 
LPCWSTR lpSubKey 
);

Parameters

hKey
[in] Handle to a currently open key or one of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS

The key specified by the lpSubKey parameter must be a subkey of the key identified by hKey.

lpSubKey
[in] Pointer to a null-terminated string specifying the name of the key to delete. This parameter cannot be NULL.

Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you call FormatMessage it could fail.

Remarks

If the function succeeds, RegDeleteKey removes the specified key from the registry. The entire key, including all of its values, is removed. An application cannot call RegDeleteKey for a key that an application currently has open.

To open the key, use the RegCreateKeyEx or RegOpenKeyEx function.


posted on 2010-08-21 12:00 Platox 阅读(687) 评论(0)  编辑 收藏 引用 所属分类: Wince

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理