I was wondering if anyone has code to replace the "standard" Windows Regsvr32. I would hate to spoil my tiny PB exe by shelling out to Regsvr32.
Thanks In Advance,
Rich
Thanks In Advance,
Rich
STDAPI DllRegisterServer(void);
STDAPI DllUnregisterServer(void);
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 Private Function RegUnReg(ByVal inFileSpec As String, Optional Register As Boolean = True) 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 As Long Dim mResult As Long ' Load the control DLL lLib = LoadLibrary(inFileSpec) If lLib = 0 Then ' e.g. file not exists or not a valid DLL file RegUnReg = "ERROR: Failure loading control DLL" Exit Function End If ' Find and store the DLL entry point If Register Then lpDLLEntryPoint = GetProcAddress(lLib, "DllRegisterServer") Else lpDLLEntryPoint = GetProcAddress(lLib, "DllUnregisterServer") End If If lpDLLEntryPoint = vbNull Then RegUnReg = "ERROR: Failed in obtaining entry point. Not a ActiveX DLL/OCX." 'Decrements the reference count of loaded DLL module before leaving FreeLibrary lLib Exit Function End If ' Create a thread to execute within the virtual address space of the calling process mThread = CreateThread(ByVal 0, 0, ByVal lpDLLEntryPoint, ByVal 0, 0, lpThreadID) If mThread = 0 Then RegUnReg = "ERROR: Failed in creating processing thread." 'Decrements the reference count of loaded DLL module before leaving FreeLibrary lLib Exit Function End If ' Use WaitForSingleObject to check the return state (i) when the specified object ' is in the signaled state or (ii) when the time-out interval elapses. mResult = WaitForSingleObject(mThread, 10000) If mResult <> 0 Then RegUnReg = "ERROR: Failed in signaled state or time-out." FreeLibrary lLib ' Terminate the thread to free up resources that are used by the thread ' NOTE: Calling ExitThread for an application's primary thread will cause ' the application to terminate lpExitCode = GetExitCodeThread(mThread, lpExitCode) ExitThread lpExitCode End If ' Don't call the dangerous TerminateThread() VB doesnt like it. After the last handle ' to the object is closed, the object is removed from the memory. CloseHandle mThread FreeLibrary lLib End Function
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment