用VB5读写注册表实例
首先新建一个工程,在新建的窗体上添加以下控件并设置相应属性:
控件名 属性 值
Label1 Caption 注册表键值:
Label2 Caption 注册姓名:
Label3 Caption 空
Label4 Caption 注册公司:
Label5 Caption 空
Label6 Caption 空
Text1 Text 空
Text2 Text 空
Command1 Caption 写入注册表
Command2 Caption 退出
然后,在程序的声明部分添加如下代码:
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Const error_success = 0&
Const error_baddb = 1009&
Const error_badkey = 1010&
Const error_cantopen = 1011&
Const error_cantread = 1012&
Const error_cantwrite = 1013&
Const error_registry_recovered = 1014&
Const error_registry_corrupt = 1015&
Const error_registry_io_failed = 1016&
Const hkey_classes_root = &H80000000
Const hkey_current_user = &H80000001
Const hkey_local_machine = &H80000002
Const REG_SZ = 1
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余3页未读,立即下载