标题:在VB6里的ACTIVEX DLL中操作注册表
只看楼主
chenrifu2005
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-7-2
 问题点数:0 回复次数:1 
在VB6里的ACTIVEX DLL中操作注册表

我现在是用VB6开发ActiveX DLL,通过ASP来调用的DLL里的函数

而现在碰到的问题是,想在DLL里操作注册表,没有成功!于是我把代码复制到VB的EXE工程里试了一下,发现成功了.

不同的地方在:DLL里是通过调用来驱动,而EXE工程里是通过按钮的事件来驱动.

操作注册表的代码如下:
'根键常数
Const HKEY_CLASSES_ROOT = -2147483648#
Const HKEY_CURRENT_USER = -2147483647#
Const HKEY_LOCAL_MACHINE = -2147483646#
Const HKEY_USERS = -2147483645#

'键值类型
Const REG_SZ = 1& '字符串值
Const REG_BINARY = 3& '二进制值
Const REG_DWORD = 4& 'DWORD 值

'声明有关API函数
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByRef phkResult As Long _
) As Long '建立一个新的主键

Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByRef phkResult As Long _
) As Long '打开一个主键

Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String _
) As Long '删除一个主键

Private Declare Function RegCloseKey Lib "advapi32.dll" _
( _
ByVal hKey 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, _
ByVal lpData As Any, _
ByVal cbData As Long _
) As Long '创建或改变一个键值,lpData应由缺省的ByRef型改为ByVal型

Private 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 '查询一个键值,lpData应由缺省的ByRef型改为ByVal型

Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String _
) As Long '删除一个键值

'主过程
Sub Main()
Dim nKeyHandle As Long, nValueType As Long, nLength As Long
Dim sValue As String
sValue = "I am a winner!"

Call RegCreateKey(HKEY_CURRENT_USER, "SuperCRM", nKeyHandle)
Call RegSetValueEx(nKeyHandle, "My Value", 0, REG_SZ, sValue, 255)
sValue = Space(255)
nLength = 255
Call RegQueryValueEx(nKeyHandle, "My Value", 0, nValueType, sValue, nLength)
MsgBox sValue
Call RegDeleteValue(nKeyHandle, "My Value")
Call RegDeleteKey(HKEY_CURRENT_USER, "New Registry Key")
Call RegCloseKey(nKeyHandle)
End Sub

'这里是按钮的事件
Private Sub Command1_Click()
Call Main
End Sub

后来在网上搜索了一下,把代码的第一部分改成:
Public Enum enumReg
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
KEY_ALL_ACCESS = &H3F
REG_OPTION_NON_VOLATILE = 0
End Enum
还是不行,请高手门尽快帮忙解决一下.

搜索更多相关主题的帖子: ACTIVEX 注册表 DLL 
2007-07-04 20:47
chenrifu2005
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-7-2
得分:0 

怎么没有人顶一下?

自己顶!

说明一下,这段代码在EXE工程里是可以正常运行和显示的,但放到DLL里再通过ASP页面来调用就不行了,请指教一下.

2007-07-05 14:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-152776-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.149591 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved