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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect if an active x control is installed

Status
Not open for further replies.

chriscboy

Programmer
Joined
Apr 23, 2002
Messages
150
Location
GB
Can someone give me some pointers on how to detect if an active-x control or DLL is installed on a PC? (e.g. MYCONTROL.OCX or CEUTIL.DLL)

I am trying to prevent the open dialog box and the error "OLE class is not registered" from occuring if a user runs a particular option in my program and hasn't got the correct controls installed. Instead I would like to display a more user friendly dialog box to avoid scareing the user.

Thanks in advance.
 
chriscboy

Trap the error using ON ERROR.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
chriscboy,

There are two schools of thought here. You could wrap the CREATEOBJECT statement in an ON ERROR or TRY/CATCH and trap any errors that way.

You could also check the registry using the registry class that ships with VFP. You can cut and paste this code to try it out. You'll just need to make sure you can see the registry class (.PRG or .VCX depending on which Foxpro version you are using):

Code:
? CheckKey("word.application") 
? CheckKey("mswinsock.winsock") 
? CheckKey("dummy.noexist") 
RETURN


PROCEDURE CheckKey
LPARAMETERS zcKey
* Registry roots
#DEFINE HKEY_CLASSES_ROOT    -2147483648  && BITSET(0,31)
#DEFINE HKEY_CURRENT_USER    -2147483647  && BITSET(0,31)+1
#DEFINE HKEY_LOCAL_MACHINE   -2147483646  && BITSET(0,31)+2
#DEFINE HKEY_USERS           -2147483645  && BITSET(0,31)+3
SET PROCEDURE TO registry ADDITIVE
LOCAL llReturn, loReg
llReturn = .F.
loReg = CREATEOBJECT("registry")
IF loReg.IsKey(zcKey, HKEY_CLASSES_ROOT)
	llReturn = .T.
ENDIF
RELEASE loReg
RELEASE PROCEDURE registry
RETURN llReturn

Andy
 
Here is a ready-to-go registry solution:


(one reason I prefer not to trap the error is that Windows Installer will sometimes jump in the way when something isn't registered and try to install it... of course, it still might if the "something" is registered to activate Windows Installer....)
 
Thanks for your help guys! I ended up going for the solution in the fox wiki.

By using the IsActiveXReg function in the Load event of my forms I can prevent the open dialog box from appearing if a control is not registered.

 
The registry read, as others have suggested, is the say to go. I wrote an FAQ on it that may help and it discusses briefly discussing registering a control.

The trick is that you need to know the registry entry name of the control. You can usually find that by looking thru the registry of a system that has the control installed.

Read the Windows Registry
faq184-4674



Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top