User Guide

Table Of Contents
960 Chapter 38: Integrating COM and CORBA Objects in CFML Applications
<h3>Getting fixed drive available space</h3>
<cfoutput>Execution Time: #int(getTickCount()-start)# milliseconds</
cfoutput><br><br>
<cfdump label="Drive Free Space" var="#driveInfo#">
Example 2: Using the Microsoft Word application object
The following example uses the Microsoft Word application COM object in the Application
scope to convert a Word document to HTML. This example works with Word 2000 as written.
To work with Word 97, change “Val(8)” to “Val(10)”.
This example uses an Application scope lock to ensure that no other page interrupts creating the
object. Once the Word object exists, the example uses a named lock to prevent simultaneous
access to the file that is being converted.
<cfapplication name="comtest" clientmanagement="No" Sessionmanagement="yes">
<!--- Uncomment the following line if you need to delete the object from the
Application scope --->
<!--- <cfset structdelete(Application, "MyWordObj")> --->
<!--- use the GetTickCount function to get a current time indicator, used for
displaying the total processing time. --->
<cfset start = GetTickCount()>
<!--- If necessary, create the Word.application object and put it in the
Application scope --->
<cfset WordObj_is_initialized = False>
<cflock scope="application" type="readonly" timeout=120>
<cfset WordObj_is_initialized = StructKeyExists(application, "MyWordObj")>
</cflock>
<cfif not WordObj_is_initialized >
<cflock scope="Application" type="exclusive" timeout="120">
<cfif not StructKeyExists(application, "MyWordObj")>
<!--- First try to connect to an existing Word object --->
<cftry>
<cfobject type="com"
action="connect"
class="Word.application"
name="Application.MyWordobj"
context="local">
<cfcatch>
<!--- There is no existing object, create one --->
<cfobject type="com"
action="Create"
class="Word.application"
name="Application.MyWordobj"
context="local">
</cfcatch>
</cftry>
<cfset Application.mywordobj.visible = False>
</cfif>
</cflock>
</cfif>