我該怎么去定義子程序和函數(shù)的問題?。〖?/h1>
3 回答

TA貢獻1864條經(jīng)驗 獲得超6個贊
該函數(shù)是API函數(shù),將下面代碼保存為Reg.Bas就可以正常使用了。
'養(yǎng)成好習(xí)慣代表所有變量都需要先定義后使用
Option Explicit
'根鍵常數(shù)
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006
'鍵值類型
Public Const REG_NONE = 0
Public Const REG_SZ = 1 '字符串值
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3 '二進制值
Public Const REG_DWORD = 4 'DWORD 值
Public Const REG_DWORD_BIG_ENDIAN = 5
Public Const REG_MULTI_SZ = 7
'----聲明有關(guān)注冊表API函數(shù) --Start----
'建立一個新的主鍵
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByRef phkResult As Long _
) As Long
'打開一個主鍵 返回0代表打開成功,返回2代表打開失敗
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByRef phkResult As Long _
) As Long
'刪除一個主鍵
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String _
) As Long
'關(guān)閉一個主鍵 返回0代表關(guān)閉成功,6代表關(guān)閉失敗
Public Declare Function RegCloseKey Lib "advapi32.dll" _
( _
ByVal hKey As Long _
) As Long
'創(chuàng)建或改變一個鍵值,lpData應(yīng)由缺省的ByRef型改為ByVal型
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
ByVal lpData As Any, _
ByVal cbData As Long _
) As Long
'查詢一個鍵值,lpData應(yīng)由缺省的ByRef型改為ByVal型
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
ByRef lpType As Long, _
ByVal lpData As Any, _
ByRef lpcbData As Long _
) As Long
'刪除一個鍵值
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String _
) As Long
'----聲明有關(guān)注冊表API函數(shù) End----

TA貢獻1824條經(jīng)驗 獲得超6個贊
在聲明里加上
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
其他幾個注冊表函數(shù)也要聲明

TA貢獻1869條經(jīng)驗 獲得超4個贊
API函數(shù)還沒定義,不能直接調(diào)用
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 RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (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
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
添加回答
舉報