When you use COM objects, consider the following to prevent and resolve errors:
Improper threading can cause serious problems when using a COM object in ColdFusion. Make sure that the object is thread-safe. An object is thread-safe if it can be called from many programming threads simultaneously, without causing errors.
Visual Basic ActiveX DLLs are typically not thread-safe. If you use such a DLL in ColdFusion, you can make it thread-safe by using the OLE/COM Object Viewer to change the object's threading model to the Apartment model.
If you are planning to store a reference to the COM object in the Application, Session, or Server scope, do not use the Apartment threading model. This threading model is intended to service only a single request. If your application requires you to store the object in any of these scopes, keep the object in the Both threading model, and lock all code that accesses the object, as described in Locking code with cflock.
Change the threading model of a COM Object
Using input and output arguments
COM object method in arguments are passed by value. The COM object gets a copy of the variable value, so you can specify a ColdFusion variable without surrounding it with quotation marks.
COM object out method arguments are passed by reference. The COM object modifies the contents of the variable on the calling page, so the calling page can use the resulting value. To pass a variable by reference, surround the name of an existing ColdFusion variable with quotation marks. If the argument is a numeric type, assign the variable a valid number before you make the call. For example:
<cfset inStringArg="Hello Object"> <cfset outNumericArg=0> <cfset result=myCOMObject.calculate(inStringArg, "outNumericArg")>
The string "Hello Object" is passed to the object's calculate method as an input argument. The value of outNumericArg is set by the method to a numeric value.
Understanding common COM-related error messages
The following table described some error messages you might encounter when using COM objects:
Error |
Cause |
---|---|
Error Diagnostic Information Error trying to create object specified in the tag. COM error 0x800401F3. Invalid class string. |
The COM object is not registered or does not exist. |
Error Diagnostic Information Error trying to create object specified in the tag. COM error 0x80040154. Class not registered. |
The COM object is not registered or does not exist. This error usually occurs when an object existed previously, but was uninstalled. |
Error Diagnostic Information Failed attempting to find "SOMEMETHOD" property/method on the object COM error 0x80020006. Unknown name. |
The COM object was instantiated correctly, but the method you specified does not exist. |