Register dll - William - 11-01-2007
Code: DLL_Register App.Path & "\file.dll"
Code: Option Explicit
Private Declare Function LoadLibraryRegister Lib "KERNEL32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibraryRegister Lib "KERNEL32" Alias "FreeLibrary" (ByVal hLibModule As Long) As Long
Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
Private Declare Function GetProcAddressRegister Lib "KERNEL32" Alias "GetProcAddress" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CreateThreadForRegister Lib "KERNEL32" Alias "CreateThread" (lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpparameter 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 Const STATUS_WAIT_0 = &H0
Private Const WAIT_OBJECT_0 = ((STATUS_WAIT_0) + 0)
Private Const NOERRORS As Long = 0
Private Enum stRegisterStatus
stFileCouldNotBeLoadedIntoMemorySpace = 1
stNotAValidActiveXComponent = 2
stActiveXComponentRegistrationFailed = 3
stActiveXComponentRegistrationSuccessful = 4
stActiveXComponentUnRegisterSuccessful = 5
stActiveXComponentUnRegistrationFailed = 6
stNoFileProvided = 7
End Enum
#If False Then
Private stFileCouldNotBeLoadedIntoMemorySpace
Private stNotAValidActiveXComponent
Private stActiveXComponentRegistrationFailed
Private stActiveXComponentRegistrationSuccessful
Private stActiveXComponentUnRegisterSuccessful
Private stActiveXComponentUnRegistrationFailed
Private stNoFileProvided
#End If
Public Function DLL_Register(ByVal p_sFileName As String) As Variant
Dim lLib As Long
Dim lProcAddress As Long
Dim lThreadID As Long
Dim lSuccess As Long
Dim lExitCode As Long
Dim lThreadHandle As Long
Dim lRet As Long
On Error GoTo ErrorHandler
If lRet = NOERRORS Then
If p_sFileName = "" Then
lRet = stNoFileProvided
End If
End If
If lRet = NOERRORS Then
lLib = LoadLibraryRegister(p_sFileName)
If lLib = 0 Then
lRet = stFileCouldNotBeLoadedIntoMemorySpace
End If
End If
If lRet = NOERRORS Then
lProcAddress = GetProcAddressRegister(lLib, "DllRegisterServer")
If lProcAddress = 0 Then
lRet = stNotAValidActiveXComponent
Else
lThreadHandle = CreateThreadForRegister(0, 0, lProcAddress, 0, 0, lThreadID)
If lThreadHandle 0 Then
lSuccess = (WaitForSingleObject(lThreadHandle, 10000) = WAIT_OBJECT_0)
If lSuccess = 0 Then
Call GetExitCodeThread(lThreadHandle, lExitCode)
Call ExitThread(lExitCode)
lRet = stActiveXComponentRegistrationFailed
Else
lRet = stActiveXComponentRegistrationSuccessful
End If
End If
End If
End If
ExitRoutine:
DLL_Register = lRet
If lThreadHandle 0 Then
Call CloseHandle(lThreadHandle)
End If
If lLib 0 Then
Call FreeLibraryRegister(lLib)
End If
Exit Function
ErrorHandler:
lRet = Err.Number
GoTo ExitRoutine
End Function
Private Function DLL_UnRegister(ByVal p_sFileName As String) As Variant
Dim lLib As Long
Dim lProcAddress As Long
Dim lThreadID As Long
Dim lSuccess As Long
Dim lExitCode As Long
Dim lThreadHandle As Long
Dim lRet As Long
On Error GoTo ErrorHandler
If lRet = NOERRORS Then
If p_sFileName = "" Then
lRet = stNoFileProvided
End If
End If
If lRet = NOERRORS Then
lLib = LoadLibraryRegister(p_sFileName)
If lLib = 0 Then
lRet = stFileCouldNotBeLoadedIntoMemorySpace
End If
End If
If lRet = NOERRORS Then
lProcAddress = GetProcAddressRegister(lLib, "DllUnregisterServer")
If lProcAddress = 0 Then
lRet = stNotAValidActiveXComponent
Else
lThreadHandle = CreateThreadForRegister(0, 0, lProcAddress, 0, 0, lThreadID)
If lThreadHandle 0 Then
lSuccess = (WaitForSingleObject(lThreadHandle, 10000) = WAIT_OBJECT_0)
If lSuccess = 0 Then
Call GetExitCodeThread(lThreadHandle, lExitCode)
Call ExitThread(lExitCode)
lRet = stActiveXComponentUnRegistrationFailed
Else
lRet = stActiveXComponentUnRegisterSuccessful
End If
End If
End If
End If
ExitRoutine:
DLL_UnRegister = lRet
If lThreadHandle 0 Then
Call CloseHandle(lThreadHandle)
End If
If lLib 0 Then
Call FreeLibraryRegister(lLib)
End If
Exit Function
ErrorHandler:
lRet = Err.Number
GoTo ExitRoutine
End Function
- Obsidian - 11-01-2007
Why not just make a batch File, and just do....
cp file.dll C:/windows/system32/file.dll
regsvr32 file.dll
?
Accomplishes the same thing with far less code. (Not that i'm crapping on your code, just an easier alternative IMO)
- William - 11-01-2007
Yeah, but for example for a engine. Some new people dont know how to register dlls and ocx, and they might need a different one that isn't already in the folder. So then that could be a inbuilt option to type the name in a external program and it registers it for example..
- Da Undead - 17-04-2007
Can you explain this more on how to use?
-Ty
- William - 18-04-2007
Just add the long code you got there into a module. Then add this code for example in form_load or in a command button to register:
Code: DLL_Register App.Path & "\file.dll"
file.dll is the filename of the file you want to register.
- Da Undead - 19-04-2007
alright thanks, is it possible to make a new module and add that into it and it still be able to read from it?
Oh and will this be able to register OCX's too?
- Tony - 20-04-2007
Da Undead Wrote:alright thanks, is it possible to make a new module and add that into it and it still be able to read from it?
Oh and will this be able to register OCX's too?
Try it and find out...
- Da Undead - 20-04-2007
well how would i know if it works, it doesn't display a message or anything when i run it >.>
- Tony - 20-04-2007
Da Undead Wrote:well how would i know if it works, it doesn't display a message or anything when i run it >.>
-_____-" then how the fuck will you know DLL are registered properly? Don't use it?
- William - 20-04-2007
Hehe you have to trust that it works, if its not showing a error. Id say it works. To spice it up some too. You could always put a:
Code: Call msgbox("The file is registered successfull")
- Da Undead - 20-04-2007
Ok heres my addon to the DLL which checks to see if file already exist and if not create it but it doesn't check idk why and it won't create if not there 
Heres my code for main menu sub load
Code: Private Sub Form_Load()
If SystemFileExist("Windows\System32\dx7vb.dll") And SystemFileExist("Windows\System32\msstdfmt.dll") And SystemFileExist("Windows\System32\MSCOMCTL.ocx") And SystemFileExist("Windows\System32\MSWINSCK.ocx") And SystemFileExist("Windows\System32\richtx32.ocx") And SystemFileExist("Windows\System32\TABCTL3N.ocx") Then
Call MsgBox("Game loaded successfull!")
Else
DLL_Register App.Path & "\Extras\register-files\dx7vb.dll"
DLL_Register App.Path & "\Extras\register-files\msstdfmt.dll"
DLL_Register App.Path & "\Extras\register-files\MSCOMCTL.ocx"
DLL_Register App.Path & "\Extras\register-files\MSWINSCK.ocx"
DLL_Register App.Path & "\Extras\register-files\richtx32.ocx"
DLL_Register App.Path & "\Extras\register-files\TABCTL3N.ocx"
Call MsgBox("The registery files have registered successfull!")
End If
End Sub
oh and i had to create a new function to work with it..
Code: Function SystemFileExist(ByVal FileName As String) As Boolean
If Dir("C:" & "\" & FileName) = "" Then
SystemFileExist = False
Else
SystemFileExist = True
End If
End Function
Any idea on how to fix?
- Robin - 20-04-2007
Da Undead Wrote:Ok heres my addon to the DLL which checks to see if file already exist and if not create it but it doesn't check idk why and it won't create if not there 
Heres my code for main menu sub load
Code: Private Sub Form_Load()
If SystemFileExist("Windows\System32\dx7vb.dll") And SystemFileExist("Windows\System32\msstdfmt.dll") And SystemFileExist("Windows\System32\MSCOMCTL.ocx") And SystemFileExist("Windows\System32\MSWINSCK.ocx") And SystemFileExist("Windows\System32\richtx32.ocx") And SystemFileExist("Windows\System32\TABCTL3N.ocx") Then
Call MsgBox("Game loaded successfull!")
Else
DLL_Register App.Path & "\Extras\register-files\dx7vb.dll"
DLL_Register App.Path & "\Extras\register-files\msstdfmt.dll"
DLL_Register App.Path & "\Extras\register-files\MSCOMCTL.ocx"
DLL_Register App.Path & "\Extras\register-files\MSWINSCK.ocx"
DLL_Register App.Path & "\Extras\register-files\richtx32.ocx"
DLL_Register App.Path & "\Extras\register-files\TABCTL3N.ocx"
Call MsgBox("The registery files have registered successfull!")
End If
End Sub
oh and i had to create a new function to work with it..
Code: Function SystemFileExist(ByVal FileName As String) As Boolean
If Dir("C:" & "\" & FileName) = "" Then
SystemFileExist = False
Else
SystemFileExist = True
End If
End Function
Any idea on how to fix?
I would make a little loop rather than a massive If... then statement, and at the moment, if one file is missing, it registers everything.
Loop through those files, if it is missing, copy and register, else skip.
Try that.
- Da Undead - 21-04-2007
Thanks but idk how to loop :\ Isnt it like an array?
- Da Undead - 21-04-2007
I fixed it by changing the function but its not registering the file if its not there...
|