Automated ActiveX registration

J

Joel Wiseheart

Is there a way through VBA code to register an ActiveX
control (Calendar Control in this particular case). I
wrote a piece of code that automates adding references,
but I don't have one for automating ActiveX registration.

I'm trying to avoid having to go from PC to PC for anyone
this application is deployed to, and registering it
manually.

Thanks,
Joel
 
C

Conor O'Doherty

Hi Joel

I beleive you on the same lines as us, we wrote a startup program for
our client a very long time ago which automatically upgrades the client each
time he starts our app. We have a shared folder where the client look for
updates. This upgrades and registers activex and other files. Believe me
when I say this is a life saver techinque, especially in a multi client
enviroment, it completely self maintainable.

Anyway, here a piece of code I found somewhere on the net. I don't know
who was the original author as it dosen't contain and comments to hint.
There is something you should know.

1. Self-reg ActiveX contain exported procedures "DllRegisterServer" and
"DllUnregisterServer". The idea is to load the dll using LoadLibrary API,
find the procedure address and execute it. Simple is isnt it.

2. ActiveX EXE server must be registered by running the exe with command
line params "/REGSERVER" or "/UNREGSERVER"

3. TLB can be reg-ed by referencing Tlbinf32.dll. Create an instance of
TypeLibInfo, set the ContainingFile to the TLB and call the methods Register
or UnRegister

I hope this is what you asked for. Also note any reference to TBL must
be deployed with your app and registered. My quess it that the code is
pseudo code compiled and not native so therefore the interfaces are not
compiled in you application. If anyone has a better explination please let
me know.


CODE TO REGISTER SELF-REG ACTIVEX DLL/OCX


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)



Private Function pRegComponent(ByVal sFilePath 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 ExitHandler
'Register/Unregister DLL
If bRegister Then
sRegister = "DllRegisterServer"
Else
sRegister = "DllUnregisterServer"
End If
'Load library into current process
lLibAddress = LoadLibraryA(sFilePath)
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)
Else
'Component Registered
pRegComponent = True
Call CloseHandle(lThread)
End If
End If
End If
Call FreeLibrary(lLibAddress)
End If
ExitHandler:
Err.Clear
End Function



Regards
Conor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top