previous page
next page

Support for Scripting

Any time you run the ATL Simple Object Wizard and choose Dual as the interface type, ATL generates an interface definition for the default interface that derives from IDispatch and is marked with the dual attribute, and places it in the IDL file. Because it derives from IDispatch, our dual interface can be used by scripting clients such as Active Server Pages (ASP), Internet Explorer (IE), and Windows Script Host (WSH). When our COM class supports IDispatch, we can use objects of that class from scripting environments. Here's an example HTML page that uses an instance of the CalcPi object:

<object classid="clsid:859512CF-E4D8-450C-AF09-6578FE2F6DC2"
        id=objPiCalculator>
</object>

<script language=vbscript>
  ' Set the digits property
  objPiCalculator.digits = 5

  ' Calculate pi
  dim pi
  pi = objPiCalculator.CalcPi

  ' Tell the world!
  document.write "Pi to " & objPiCalculator.digits & _
    " digits is " & pi
</script>

For more information about how to handle the inconvenient data types associated with scriptingnamely, BSTRs and VARIANTssee Chapter 2, "Text and Strings," and Chapter 3, "ATL Smart Types."


previous page
next page
Converted from CHM to HTML with chm2web Pro 2.75 (unicode)