Consultor Eletrônico



Kbase 18195: ACTIVEX - How To Find Out At Runtime If An OCX Is Registered
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   15/10/2008
Status: Verified

GOAL:

How to tell if an OCX is registered.

GOAL:

How do I tell if an OCX is registered on the end users system other than just
running my program and seeing if it fails?

FIX:

This solution gives one way to check that OCX controls are registered before running the .W's and finding that they fail.

The following function accepts a comma delimited list of OCX ProgID's and attempts to instantiate an instance of each one.  The function returns TRUE if it was able to instantiate an instance of each object and FALSE if even one of the objects was unable to be instantiated.

Comments in the code point out where developers may want to expand the functionality of the code by displaying message boxes, or by attempting to find the OCX and register it.

To obtain the ProgID for an OCX control, use the Registry Editor (REGEDIT).  As an example, the following steps show you how to find the ProgID for the PSTIMER.OCX which ships with Progress.  Follow the same steps for each OCX that you use in your application.


-  Run REGEDIT.
-  Select FIND from the EDIT menu.
-  Type PSTIMER.OCX in the "Find What:" field.
-  Deselect the KEYS check box.
-  Deselect the VALUES check box.
-  Deselect the MATCH WHOLE STRING ONLY check box.
-  Select the DATA check box.
-  Click the FIND NEXT button.

At this point, REGEDIT will search the registry for any occurrence of PSTIMER.OCX.  Please keep in mind that there may be multiple occurrences of what you are searching for.  For each occurrence of PSTIMER.OCX look at the tree view in the left pane of the registry editor.  What you are looking for is a subkey named ProgID.  When you find this subkey, write down the value associated with the subkey.  In the case of PSTIMER.OCX the value is "PSTIMER.PSTimerCtrl.1".

When you are finished doing the above steps for all of the OCX controls you use in your application you should put them all together in a single comma delimited list and pass that list to the function defined below.

FUNCTION AreControlsRegistered
        RETURNS LOGICAL (INPUT ChrObjectList AS CHARACTER):

   DEFINE VARIABLE logRC      AS LOGICAL    NO-UNDO INITIAL True.
   DEFINE VARIABLE intCnt     AS INTEGER    NO-UNDO.
   DEFINE VARIABLE hdlCheckIt AS COM-HANDLE NO-UNDO.

   DO intCnt = 1 TO NUM-ENTRIES(chrObjectList):
       CREATE VALUE(ENTRY(intCnt,chrObjectList)) hdlCheckIt NO-ERROR.
       IF ERROR-STATUS:ERROR = False THEN
           RELEASE OBJECT hdlCheckIt NO-ERROR.
       ELSE
           ASSIGN logRC = False.
           /*
            *
            * You can put code here to do more in-depth handling
            * of the fact that the object is not registered.
            *
            * One idea is to attempt to locate and register the
            * control using regsvr32.exe (assuming that it exists
            * on the users system).
            */
   END.

   RETURN logRC.

END FUNCTION.