| Mirage Source http://miragesource.net/forums/ |
|
| Register dll http://miragesource.net/forums/viewtopic.php?f=210&t=1139 |
Page 1 of 2 |
| Author: | William [ Thu Jan 11, 2007 12:52 pm ] |
| Post subject: | Register dll |
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 |
|
| Author: | Obsidian [ Thu Jan 11, 2007 7:05 pm ] |
| Post subject: | |
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) |
|
| Author: | William [ Thu Jan 11, 2007 8:21 pm ] |
| Post subject: | |
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.. |
|
| Author: | Da Undead [ Tue Apr 17, 2007 10:39 pm ] |
| Post subject: | |
Can you explain this more on how to use? -Ty |
|
| Author: | William [ Wed Apr 18, 2007 12:37 pm ] |
| Post subject: | |
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. |
|
| Author: | Da Undead [ Thu Apr 19, 2007 11:23 pm ] |
| Post subject: | |
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? |
|
| Author: | Tony [ Fri Apr 20, 2007 12:18 am ] |
| Post subject: | |
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... <.< |
|
| Author: | Da Undead [ Fri Apr 20, 2007 12:39 am ] |
| Post subject: | |
well how would i know if it works, it doesn't display a message or anything when i run it >.> |
|
| Author: | Tony [ Fri Apr 20, 2007 4:59 am ] |
| Post subject: | |
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? |
|
| Author: | William [ Fri Apr 20, 2007 9:24 am ] |
| Post subject: | |
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")
|
|
| Author: | Da Undead [ Fri Apr 20, 2007 9:10 pm ] |
| Post subject: | |
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? |
|
| Author: | Robin [ Fri Apr 20, 2007 9:58 pm ] |
| Post subject: | |
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. |
|
| Author: | Da Undead [ Sat Apr 21, 2007 1:05 am ] |
| Post subject: | |
Thanks but idk how to loop :\ Isnt it like an array? |
|
| Author: | Da Undead [ Sat Apr 21, 2007 3:24 pm ] |
| Post subject: | |
I fixed it by changing the function but its not registering the file if its not there... |
|
| Page 1 of 2 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|