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

Help using COM 1

Status
Not open for further replies.

klaforce

Programmer
Mar 25, 2005
124
US
Hi, I am developing an application that will read a Microsoft Word Document and display it as HTML. I am using the following code, which is an example off of livedocs. However, I am getting this error message:

An exception occurred when instantiating a Com object.
The cause of this exception was that: coldfusion.runtime.java.JavaObjectInstantiationException: Object Instantiation Exception..

The error occurred in C:\CFusionMX\ line 30
Called from C:\CFusionMX\ line 30
Called from C:\CFusionMX\ line 30

28 : <cfobject type="com"
29 : action="Create"
30 : class="Word.Application"
31 : name="Application.MyWordobj"
32 : context="local">


Code:
<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>

<!--- Convert a Word document in temp.doc to an HTML file in temp.htm. --->
<!--- Because this example uses a fixed filename, multiple pages might try
   to use the file simultaneously. The lock ensures that all actions from
   reading the input file through closing the output file are a single "atomic"
   operation, and the next page cannot access the file until the current page
   completes all processing. 
   Use a named lock instead of the Application scope lock to reduce lock contention. --->
<cflock name="WordObjLock" type="exclusive" timeout="120">
   <cfset docs = application.mywordobj.documents()>
   <cfset docs.open("C:\Documents and Settings\N537252\Desktop\test.doc")>
   <cfset converteddoc = application.mywordobj.activedocument>
   <!--- Val(8) works with Word 2000. Use Val(10) for Word 97 --->
   <cfset converteddoc.saveas("C:\Documents and Settings\N537252\Desktop\temp.htm",val(8))>
   <cfset converteddoc.close()>
</cflock>

<cfoutput>
   Conversion of temp.htm Complete<br>
   Execution Time: #int(getTickCount()-start)# milliseconds<br>
</cfoutput>

Thank you for your help in advance.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
Also, it is my local machine that I have CF installed on, and Word is installed too.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
make sure cfobject is enabled.

Beware of programmers who carry screwdrivers.
 
Where is that setting at? I read that it is supposed to be under basic security, but I can not find it. I see Sandbox Security, and then the two passwords (ColdFusion Admin and RDS).


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
Well I discovered that if you setup a sandbox you can disable and enable tags, is this what you meant? If so, then I did not have any sandboxes enabled, and so cfobject should be okay.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
in the menu at the very bottom a link that reads "resource security" in the tags menu make sure it isn't disabled.

Beware of programmers who carry screwdrivers.
 
What version are you running? I am running 6.1, and I do not see a resource security option in the menu. Here are my options:

Server Settings:
Settings
Caching
Client Variables
Memory Variables
Mappings
Mail
Charting
Java and JVM
Archives and Deployment
Settings Summary
Data & Services:
Data Sources
Verity Collections
Verity K2 Server
Web Services
Debugging & Logging:
Debugging Settings
Debugging IP Addresses
Logging Settings
Log Files
Scheduled Tasks
System Probes
Code Analyzer
Extensions:
Java Applets
CFX Tags
Custom Tag Paths
CORBA Connectors
Security:
CF Admin Password
RDS Password
Sandbox Security



Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
6.1 standard. guess the menus are a bit different from dev edition.

Beware of programmers who carry screwdrivers.
 
Yeah your right, I looked at our 6.1 standard, and it has resource security, but looks almost identical to the Sandbox one I have. Thus, cfobject is not disabled.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
Hi klaforc,

Make sure that the MS Word service can interact with your desktop. I remember having to check this setting on previous jobs, goto "Computer Management", click on the services tab and find the MS Word Service (I don't know the exact name of it). Right click and goto properties. Click on the 'Log On' tab and then check off the box that says "Allow service to interact with desktop".

I'm not entirely positive that this will correct your issue or is even attributed to it, but I think that you need this setting to properly connect to the MS word com object.

hope this helps,

jalpino
 
Hi Jalp, thanks for your reply. I do not see a service related to MS Word. Can you remember the exact name? Thanks again.



Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
Hi klaforc,

Its the 'Coldfusion Application server' service. I couldn't remember distinctly what it was, I thought it was an MS specific service but after talking to a friend he told me it was the CF service. Give it a try and let us know if it resolved your issue.

jalpino
 
Thanks jalpina that got me somewhere at least. Now I know that is beginning to initialize because I get the Windows installer to pop up (even though it is installed) with a 1325 Error Templates is not a valid short name, but I think this is a separate issue. I will post here when I find the solution. Thanks again jalpina.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top