请各位大虾一看看!DLL的问题!急急!!!!!!!!!!!
我初学!现遇一问题,DLL的调用有问题出现对象不支持该属性或方法
Private Function WriteRegKey(ByVal KeyRoot As REGRoot, _
ByVal KeyName As String, _
ByVal SubKeyName As String, _
ByVal SubKeyType As REGValueType, _
ByVal SubKeyValue As String _
) As Boolean
Dim rc As Long ' 返回代码
Dim hKey As Long ' 处理一个注册表关键字
Dim hDepth As Long '
Dim lpAttr As SECURITY_ATTRIBUTES ' 注册表安全类型
Dim i As Integer
Dim bytValue(1024) As Byte
Dim intNum As Integer
lpAttr.nLength = 50 ' 设置安全属性为缺省值...
lpAttr.lpSecurityDescriptor = 0
lpAttr.bInheritHandle = True
'------------------------------------------------------------
'- 创建/打开注册表关键字...
'------------------------------------------------------------
rc = RegCreateKeyEx(KeyRoot, _
KeyName, _
0, _
SubKeyType, _
REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
lpAttr, _
hKey, _
hDepth _
) ' 创建/打开//KeyRoot//KeyName
If (rc <> ERROR_SUCCESS) Then GoTo CreateKeyError ' 错误处理...
'------------------------------------------------------------
'- 创建/修改关键字值...
'------------------------------------------------------------
If (SubKeyValue = "") Then SubKeyValue = " " ' 要让RegSetValueEx() 工作需要输入一个空格...
Select Case SubKeyType ' 搜索数据类型...
Case REG_SZ, REG_EXPAND_SZ ' 字符串注册表关键字数据类型
'------------------------------------------------------------------
rc = RegSetValueEx_SZ(hKey, SubKeyName, 0, SubKeyType, ByVal SubKeyValue, LenB(StrConv(SubKeyValue, vbFromUnicode)))
If (rc <> ERROR_SUCCESS) Then GoTo CreateKeyError ' 错误处理
'------------------------------------------------------------------
Case REG_DWORD ' 四字节注册表关键字数据类型
'-------------------------------------------------------------------
rc = RegSetValueEx_DWORD(hKey, SubKeyName, 0, SubKeyType, Val("&h" + SubKeyValue), 4)
If (rc <> ERROR_SUCCESS) Then GoTo CreateKeyError ' 错误处理
'-------------------------------------------------------------------
Case REG_BINARY ' 二进制字符串
'-------------------------------------------------------------------
intNum = 0
For i = 1 To Len(Trim(SubKeyValue)) - 1 Step 3
intNum = intNum + 1
bytValue(intNum - 1) = Val("&h" + Mid(SubKeyValue, i, 2))
Next i
rc = RegSetValueEx_BINARY(hKey, SubKeyName, 0, SubKeyType, bytValue(0), intNum)
If (rc <> ERROR_SUCCESS) Then GoTo CreateKeyError ' 错误处理
'-------------------------------------------------------------------
Case Else
'--------------------------------------------------------------------
GoTo CreateKeyError ' 错误处理
'--------------------------------------------------------------------
End Select
'- 关闭注册表关键字...
'------------------------------------------------------------
rc = RegCloseKey(hKey) ' 关闭关键字
WriteRegKey = True ' 返回成功
Exit Function ' 退出
'---------------------------------------------------------------------------------------------
CreateKeyError:
WriteRegKey = False ' 设置错误返回代码
rc = RegCloseKey(hKey) ' 试图关闭关键字
End Function
上面是DLL中的
下面是调用的
Public objClsReg As Object
Set objClsReg = CreateObject("ModifyRegister.CLSREG")
Private Sub cmdOK_Click(Index As Integer)
Dim retValue As Long
Dim strSubKey As String
Dim Result As Long
Dim Res As Boolean
Dim strServer As String
strServer = Trim(cmbServer.Text)
Res = objClsReg.WriteRegKey(HKEY_LOCAL_MACHINE, strKeyValue, "ServerName", REG_SZ, strServer)
If Res= True Then
MsgBox "Success"
Else
MsgBox "Write Register Failed"
Exit Sub
End If
End Sub