Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List all dll and ocx controls 1

Status
Not open for further replies.

kiwiCoder

Technical User
Aug 2, 2001
45
NZ
Just wondering if anyone knows how to list all ocx and dll files in project.What I would like to do is be able to intercept the error that occurs when a dll,ocx is missing. Then use the name to search for and register the control from code.

If you love your job you never have to work again.
 
Intercept when? In the project or when it has been compiled. Why do you want to do this? If an ocx/dll is missing the code will not run at all and the program will end. Your program will not be able to continue.

Better to make sure all dll/ocx files needed are installed along with your application.
 
Not quite correct, a program will contiue to run after providing 479(I think) error. This error could be trapped, the name of the offending ocx\dll provided to a var which then could be used to provide info to software provider. We hsve a constantly evolvong app distributed to a large number of clients by several installers. If someone forgets to register an ocx, viola it can be done dynamically.

If you love your job you never have to work again.
 
this may help you out or not but... I know that if you view a VB executable you will see some of the ocx files that it uses, it may tell you which dll's.

So the idea is to create an external exe and have it launched (for instance when 479 is generated) to stop the original app and then to peek into the executable (in hex or binary) and do the regsvr32.

great freeware hex editor, after you install it you can right click on anything to do a hex view/edit.
 
I'd think about something like this

Code:
Private Sub Command2_Click()
Dim strObj As String
Dim intRes As Integer
'
' Class name we want an object of...
' in this case an ADO connection
'
strObj = "ADODB.Connection"

intRes = ObjectTest(strObj)

Select Case intRes
Case 0
    'Object Instanced OK
    'Do nothing
    MsgBox "Ok"
Case 1
    'Object didn't instance
    'but no error either
    MsgBox "not Ok"
    
Case 3
    'Object Not registered
    'Register it
    MsgBox "Register"
    
Case Else:
    'Unknown error thrown
    'more processing required
    MsgBox "unknown"
End Select

End Sub
Private Function ObjectTest(strObjName As String) As Integer
Dim objTestInstance As Object

On Error GoTo ErrorHandler

'see if we can create it ok
Set objTestInstance = CreateObject(strObjName)

If objTestInstance Is Nothing = False Then
    'Object created OK
    ObjectTest = 0

    'we did so tidy up object
    Set objTestInstance = Nothing
Else
    'Object Didn't Create
    'But no error either
    ObjectTest = 1
End If
Exit Function

ErrorHandler:

If Err.Number = 429 Then
    ObjectTest = 3
Else
    ObjectTest = Err.Number
End If
End Function

You will need to maintain a list of objects used (classname) which you can push through the ObjectTest function, which uses late binding to instance the object. You can test for correct instantiation and trap errors here.

The obove code is rough and ready, but points you in one direction to achieve a solution

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
errors on:

Code:
Set objTestInstance = CreateObject(strObjName)

using Ms. A. ver 2003 (ala ver XP) / ADO 2.6 in references




MichaelRed


 
What error does it throw? Have you checked your error handling is set correctly? i.e. not "Break on all errors"

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
mmmmmmmmmmmmmmmmmmmmm ... mmmmmmmmmmmm,

O.K. it was the break on (?) errors. Setting it to "Unhandled" errs, gets throught the process. That DOES raise the issue. The schema REQUIREs specific (system wide?) settings. This may not be desireable. I work (mostly) on smaller projects w/o collaboration so don't run into such issues often, but it could be a problem in a cooperative / enterprise system with other settings and multiple proigrammers. I would have thought MS would have a better way of handling the issue. If the routine (or its parent chain?) includes err handling (of course there would need to be some standard(s) for this, then use the individual procedures' (or parent chain) handling, otherwise use the app setting. I guess htis is JUST TOO MUCH to ask.



MichaelRed


 
The error handling options (Break on Unhandled erros, break in class Module, Break on all errors) applies only in the IDE. Does that explain?

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Yes. Sort of. In dev it is set, but it applies to the app, wheather dev or run. WOuld be 'nice' to be able to get curr setting (save to re-set), set to "UnHandled" for the procedure, then (after value obtained / used) re-set to what was saved.

I've startrd looking into how to do this, but haven't found the ingreedients for the soup yet. I can get to the VBE, and get some objs, properties, etc, but haven't found the objmodel structure which includes the break on ? setting(s).





MichaelRed


 
Thanks for all the help, but the initial question remains un-answered. How to write a sub that will list all ocx,dll files referenced by the project that need registered. It must be able to be done because I have seen small apps that list all project files, including ocx,dlls that need registered.
Package and Deploy does it!

Regards

If you love your job you never have to work again.
 
>Package and Deploy does it!

Package and Deploy can do it because it has access to the source code of the project. Specifically it can access the project file (vbp) and read the 'Reference=' lines to determine specific references, each form to read 'Object=' lines to determine additional controls, and has a dependency file in the P&D wizard folder that is uses to find...erm...dependencies. Of course, this only works for early bound ActiveX libraries and added controls.
 
Thanks strongm, thats it exactly. I opened the vbp in notepad and had a wee look. Should be reasonably simple to open and enumerate each line of the vbp, compare new exe references to a list of original EXE references then install and register any ocx,dll files that were not part of the original setup program.

If you love your job you never have to work again.
 
Sometimes you get the Could Not Create Object error. In my PC was working fine in my partner PC i got the error. Created a setup file and installed on his PC, same error. Copied the source code to his PC, opened in the VB editor and the program runs fine. I compiled it on his PC and the program runs fine... Knowing which dll/ocx is returning the error should be great cause I dont know what the problem is :(
Cya.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top