通过api注册控件:
Option Explicit
Private Declare Function LoadLibraryA Lib "kernel32" (ByVal lLibFileName As String) As Long
Private Declare Function CreateThread Lib "kernel32" (lThreadAttributes As Any, ByVal lStackSize As Long, ByVal lStartAddress As Long, ByVal larameter As Long, ByVal lCreationFlags As Long, lThreadID As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal lMilliseconds As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lProcName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lExitCode As Long) As Long
Private Declare Sub ExitThread Lib "kernel32" (ByVal lExitCode As Long)
'Purpose : This function registers and Unregisters OLE components
'Inputs : sDllPath The path to the DLL/OCX
' bRegister If True Registers the control, else unregisters control
'Outputs : Returns True if successful
'Author : Andrewb
'Date : 04/09/2000
'Notes : This effectively replaces RegSvr32.exe by loading the library and
' calling the register or unregister functions exposed by all OLE components.
'Revisions :
Function RegisterServer(ByVal sDllPath As String, Optional bRegister As Boolean = True) As Boolean
Dim lLibAddress As Long, lProcAddress As Long, lThreadID As Long, lSuccess As Long, lExitCode As Long, lThread As Long
Dim sRegister As String
Const clMaxTimeWait As Long = 20000 'Wait 20 secs for register to
complete
On Error GoTo ExitFunc
If Len(sDllPath) > 0 And Len(Dir(sDllPath)) > 0 Then
'File exists
If bRegister Then
sRegister = "DllRegisterServer"
Else
sRegister = "DllUnregisterServer"
End If
'Load library into current process
lLibAddress = LoadLibraryA(sDllPath)
If lLibAddress Then
'Get address of the DLL function
lProcAddress = GetProcAddress(lLibAddress, sRegister)
If lProcAddress Then
'Found interface, make call to component
lThread = CreateThread(ByVal 0&, 0&, ByVal lProcAddress, ByVal 0&, 0&, lThread)
If lThread Then
'Created thread
lSuccess = (WaitForSingleObject(lThread, clMaxTimeWait) = 0)
If Not lSuccess Then
'Failed to register, close thread
Call GetExitCodeThread(lThread, lExitCode)
Call ExitThread(lExitCode)
RegisterServer = False
Else
'Register control
RegisterServer = True
Call CloseHandle(lThread)
End If
End If
Else
'Object doesn't expose OLE interface
FreeLibrary lLibAddress
End If
Call FreeLibrary(lLibAddress)
End If
End If
ExitFunc:
On Error GoTo 0
End Function'调用
RegisterServer app.path+"\Dbgrid32.ocx",true
RegisterServer app.path+"\Dblist32.ocx",true
Option Explicit
Private Declare Function LoadLibraryA Lib "kernel32" (ByVal lLibFileName As String) As Long
Private Declare Function CreateThread Lib "kernel32" (lThreadAttributes As Any, ByVal lStackSize As Long, ByVal lStartAddress As Long, ByVal larameter As Long, ByVal lCreationFlags As Long, lThreadID As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal lMilliseconds As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lProcName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lExitCode As Long) As Long
Private Declare Sub ExitThread Lib "kernel32" (ByVal lExitCode As Long)
'Purpose : This function registers and Unregisters OLE components
'Inputs : sDllPath The path to the DLL/OCX
' bRegister If True Registers the control, else unregisters control
'Outputs : Returns True if successful
'Author : Andrewb
'Date : 04/09/2000
'Notes : This effectively replaces RegSvr32.exe by loading the library and
' calling the register or unregister functions exposed by all OLE components.
'Revisions :
Function RegisterServer(ByVal sDllPath As String, Optional bRegister As Boolean = True) As Boolean
Dim lLibAddress As Long, lProcAddress As Long, lThreadID As Long, lSuccess As Long, lExitCode As Long, lThread As Long
Dim sRegister As String
Const clMaxTimeWait As Long = 20000 'Wait 20 secs for register to
complete
On Error GoTo ExitFunc
If Len(sDllPath) > 0 And Len(Dir(sDllPath)) > 0 Then
'File exists
If bRegister Then
sRegister = "DllRegisterServer"
Else
sRegister = "DllUnregisterServer"
End If
'Load library into current process
lLibAddress = LoadLibraryA(sDllPath)
If lLibAddress Then
'Get address of the DLL function
lProcAddress = GetProcAddress(lLibAddress, sRegister)
If lProcAddress Then
'Found interface, make call to component
lThread = CreateThread(ByVal 0&, 0&, ByVal lProcAddress, ByVal 0&, 0&, lThread)
If lThread Then
'Created thread
lSuccess = (WaitForSingleObject(lThread, clMaxTimeWait) = 0)
If Not lSuccess Then
'Failed to register, close thread
Call GetExitCodeThread(lThread, lExitCode)
Call ExitThread(lExitCode)
RegisterServer = False
Else
'Register control
RegisterServer = True
Call CloseHandle(lThread)
End If
End If
Else
'Object doesn't expose OLE interface
FreeLibrary lLibAddress
End If
Call FreeLibrary(lLibAddress)
End If
End If
ExitFunc:
On Error GoTo 0
End Function'调用
RegisterServer app.path+"\Dbgrid32.ocx",true
RegisterServer app.path+"\Dblist32.ocx",true
这个问题这样我想就可以了:
第一种方法:
1,用打包软件(安装制作程序)打包你的软件。
2,在打包软件中定义一个注册表操作:
HKEY_CLASSES_ROOT\Licenses\586C75F1-EFBC-11CF-B9F3-00A0247033C4 = xybiedobrqsprbijaegcbislrsiucfjdhisl
3,这样就可以了,当你的安装程序执行时就可以把Dbgrid32.ocx许可信息添加到注册表。第二种方法:
在主程序加载过程中添加这个: Dim RetVal
RetVal = Shell("regedit -s DBGRID.REG", 1)上面程序的意思是以不提示方式导入DBGRID.REG的内容到注册表。
不过这要求DBGRID.REG与你的程序在一个文件夹下,当然你也可以指定它的路径。
这段程序将在你的程序每次执行时都执行。所以推荐用第一种方法。安装软件可以到 CSDN专用FTP 下载:
ftp://friend:[email protected]
说的不错,是有一个reg文件需要导入。请问老大能帮我看一下源程序吗?
我修改后提示错误
HKEY_CLASSES_ROOT\Licenses\586C75F1-EFBC-11CF-B9F3-00A0247033C4 = xybiedobrqsprbijaegcbislrsiucfjdhisl请问在打包过程中那里能添加这个选项
1,源程序我不看了,修改后错误是因为我上面已经说了,我笔误,已经改成:
HKEY_CLASSES_ROOT\Licenses\556C75F1-EFBC-11CF-B9F3-00A0247033C4 = xybiedobrqsprbijaegcbislrsiucfjdhisl上面有个小错误,已经改了,注意这里:“Licenses\586”改成了“Licenses\556”。2,增加注册表操作:
这里以Setupbuilder1.5为例:
前面的基本设置工作完成后,点右边的“高级设置”-左边的“登记注册表信息”-右击“HKEY_CLASSES_ROOT”-新建 项-右击“新项 #1”-重命名为“Licenses”-右击“Licenses”-新建 项-右击“新项 #1”-重命名为“556C75F1-EFBC-11CF-B9F3-00A0247033C4”-双击右边的“默认”-添加字串键值“xybiedobrqsprbijaegcbislrsiucfjdhisl”这样就可以了。3,要添加 help.chm 到安装文件夹,可以这样:
仍然以Setupbuilder1.5为例:
前面的基本设置工作完成后,点右边的“常规设置”-左边的“指定文件组和文件”-右击“Program Files”-添加文件-指定你的help.chm文件路径即可。
这样help.chm将在安装时被拷贝到安装文件夹与可执行文件在一起。
对于添加chm文件,请问vb自带的打包程序怎么弄呢