VB--注册Dll文件

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

VB--注册Dll文件

2009-04-24 13:22

如果用到编译DLL的话,在打包给别人的话,不注册DLL是运行不了的.

网上有很多方法,我把优秀的整理出来..(举例:xishuai.dll)

从简单的讲起:

如果自己的话:

regsvr32 xishuai.dll

给别人,呵呵,当然忘不了BAT了..

将下面复制到记事本,重命名为:注册组件.BAT

@echo off

regsvr32 xishuai.dll

echo 注册完成

echo

这样还要用户操作..?(哈,我们还有SHELL!!)

Private Sub Form_Load()

Shell (App.Path & "\注册组件.bat")

End Sub

这样不就OK了.(汗.MS太烦琐)

看看这个例子!:

Option Explicit

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _

(ByVal lpLibFileName As String) As Long

Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _

ByVal lpProcName As String) As Long

Private Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, _

ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lParameter As Long, _

ByVal dwCreationFlags As Long, lpThreadID As Long) As Long

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _

ByVal dwMilliseconds As Long) As Long

Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, _

lpExitCode As Long) As Long

Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode 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

Dim mresult

Dim Reg As String, Success As Boolean

Public Sub RegUnReg(ByVal inFileSpec As String, Optional inHandle As String = "")

On Error Resume Next

Dim lLib As Long ' Store handle of the control library

Dim lpDLLEntryPoint As Long ' Store the address of function called Dim lpThreadID As Long ' Pointer that receives the thread identifier Dim lpExitCode As Long ' Exit code of GetExitCodeThread

Dim mThread

' Load the control DLL, i. e. map the specified DLL file into the

' address space of the calling process

lLib = LoadLibrary(inFileSpec)

If lLib = 0 Then

' e.g. file not exists or not a valid DLL file

MsgBox "Failure loading control DLL"

Exit Sub

End If

' Find and store the DLL entry point, i.e. obtain the address of the ' 揇llRegisterServer?or "DllUnregisterServer" function (to register ' or deregister the server抯 components in the registry).

'

If inHandle = "" Then

lpDLLEntryPoint = GetProcAddress(lLib, "DllRegisterServer")

ElseIf inHandle = "U" Or inHandle = "u" Then

lpDLLEntryPoint = GetProcAddress(lLib, "DllUnregisterServer")

Else

MsgBox "Unknown command handle"

Exit Sub

End If

If lpDLLEntryPoint = vbNull Or lpDLLEntryPoint = 0 Then

GoTo earlyExit1

相关文档
最新文档