有个vb问题
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 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const REG_SZ = 1
Const HKEY_LOCAL_MACHINE = &H80000002
Private Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
Dim keyHand As Long
Dim R As Long
R = RegCreateKey(hKey, strPath, keyHand)
R = RegSetValueEx(keyHand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
R = RegCloseKey(keyHand)
End Sub
答案:RegCreateKey
VB声明
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
说明
在指定的项下创建一个新项。如指定的项已经存在,那么函数会打开现有的项
返回值
Long,零(ERROR_SUCCESS)表示成功。其他任何值都代表一个错误代码
参数表
参数 类型及说明
hKey Long,要打开项的句柄,或者一个标准项名
lpSubKey String,欲创建的新子项。可同时创建多个项,只需用反斜杠将它们分隔开即可。例如level1\level2\newkey
phkResult Long,指定一个变量,用于装载新子项的句柄
RegSetValueEx
VB声明
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
说明
设置指定项的值
返回值
Long,零(ERROR_SUCCESS)表示成功。其他任何值都代表一个错误代码
参数表
参数 类型及说明
hKey Long,一个已打开项的句柄,或指定一个标准项名
lpValueName String,要设置值的名字
Reserved Long,未用,设为零
dwType Long,要设置的数量类型
lpData Any,包含数据的缓冲区中的第一个字节
cbData Long,lpData缓冲区的长度
RegCloseKey
函数功能描述:释放指定注册键的句柄
函数原型
LONG RegCloseKey(
HKEY hKey // 释放键的句柄
);
参数
hKey : [输入] 想要关闭的已经打开的键。
返回值: 如果过程执行成功,返回值是 ERROR_SUCCESS。如果功能失败,返回一个非零值,错误码在 Winerror.h 定义。可以使用FormatMessage 函数和FORMAT_MESSAGE_FROM_SYSTEM 标记获得一个分类的错误描述。
备注: 被关闭的句柄将不可以再使用,应为已经不再有效。
其实你打开注册表看一下就知道它说的什么意思了,
在运行里输入:regedit
要是还不明白就看一下这个
http://baike.zhaoxi.net/view/1293825.htm
这个是保存注册表键值的代码
上一个:关于VB的sendmessage问题
下一个:vb获取启动文件夹路径