Environment:  VC++ 6.0

Embedding a Signed CAB File on a Web Page

ATL and MFC controls are embedded in Web pages using the <OBJECT> tag. Within the <OBJECT> tag, you need to specify three attributes for the control:

<OBJECT classid=B8748B60-E34D-42AA-9309-8012CA4964AC
        id=ScriptableLabelControl
        CODEBASE ="ScriptableActiveX.cab#version=1,0,0,1">
</OBJECT>

The ID parameter refers to the the control's name. The CLASSID parameter refers to the CLSID of the control. And, the CODEBASE parameter refers to the location from which to download the control. Note that CODEBASE can point at a number of different file types successfully.

If you include the optional version number with a CAB file, the version number should refer to the control being downloaded. For example, because ScriptableActiveX.dll has a version number of 1, 0, 0, 1, the version for the CAB is also 1, 0, 0, 1.

If you do not include the version number, older versions of the same control will not be replaced if they are found on the client machine.

Testing the Scriptable ActiveX Web Control

Adding controls by hand is not a simple process. The CLSID numbers are unwieldy to type, and it can be difficult to visualize the effects of the parameter settings on the control. To help with these difficulties, Microsoft created the ActiveX Control Pad, which can be obtained from their web site at Microsoft ActiveX Control Pad.

To test the Scriptable ActiveX Web Control with JavaScript, you may use ActiveX Control Pad to create it, or you may find it easier to lay out your page in your preferred HTML editor as the following HTML code:

<HTML>
<HEAD>
<TITLE>Scriptable ActiveX Web Control</TITLE>
<SCRIPT LANGUAGE="JavaScript">
   function NotifyActiveX(e)
   {
      if ( e.readyState != 4 ) return;
      window.setInterval("document.all.ScriptableLabelControl.
                         caption=(new Date()).toString()",1000);
   }
</SCRIPT>
<STYLE TYPE="text/css">
#ScriptableLabelControl {
   width: 250px;
   height: 25px;
   padding: 4px;
   border: thin solid #fc5;
   margin-left: 5em;
}
</STYLE>
</HEAD>

<BODY>
<OBJECT
   ID="ScriptableLabelControl"
   onReadyStateChange="NotifyActiveX(this)"
   CLASSID="CLSID:B8748B60-E34D-42AA-9309-8012CA4964AC"
   CODEBASE="ScriptableActiveX.cab">
</OBJECT>
</BODY>
</HTML>

Save this HTML code in your web server and browse it!

Internet Explorer will prompt the user before downloading and installing the ActiveX control. If Internet Explorer is attempting to install the Signed ActiveX control automatically, it shows the prompt, as shown in Figure 9.

 

Figure 9: The Signed ActiveX control's prompt

When prompted with a certificate, please accept it. When downloading and installation process are finished, the current date and time should appear, as shown in Figure 10.

 

Figure 10: Scriptable ActiveX Control

If you see the current date and time displayed properly in your browser, CONGRATULATIONS! ActiveX and scripting are working properly.

Notes:

Conclusion

For a control to be scriptable, it must follow Microsoft's object safety guidelines and be marked as safe for scripting. In this article, you examined the IObjectSafety interface and learned how a control built using ATL can take advantage of IObjectSafety. An example of a safely scriptable ActiveX control helped you explore this topic.

Go to page: Prev  1  2  3