This class is used to create Component Object Model (COM) objects.
| Method | Description | |
|---|---|---|
| attach | Attaches an instance of the COM class to a COM interface. |
| cancelTimeOut | Cancels a previous method call to the setTimeOut method. (Inherited from Object.) |
| detach | Detaches a COM object from the class with which it was associated. |
| dispatch | Reserved. Do not explicitly call this method. |
| documentationName | Returns the textual name of the COM object that is associated with the instance of the COM class. |
| equal | Determines whether the specified object is equal to the current one. (Inherited from Object.) |
| error | Returns a COMError class object that is associated with the instance of the COM class. |
| finalize | Frees resources that are associated with the instance of the COM . |
| getTimeOutTimerHandle | Returns the timer handle for the object. (Inherited from Object.) |
| handle | Retrieves the handle of the class of the object. (Inherited from Object.) |
| interface | Returns the interface that is associated with the COM object. |
| lcid | |
| new | Creates an instance of the COM class to be attached to the COM class. Optionally, this method instantiates a COM object on a specified computer. |
| notify | Releases the hold on an object that has called the wait method on this object. (Inherited from Object.) |
| notifyAll | Releases a lock on the object that was issued by the wait method on this object. (Inherited from Object.) |
| objectOnServer | Determines whether the object is on a server. (Inherited from Object.) |
| owner | Returns the instance that owns the object. (Inherited from Object.) |
| setTimeOut | Sets up the scheduled execution of a specified method. (Inherited from Object.) |
| toString | Returns a string that represents the instance of the COM class. |
| usageCount | Returns the current number of references, that is, the value of the reference counter, that the object has. (Inherited from Object.) |
| wait | Pauses a process. (Inherited from Object.) |
| xml | Returns an XML string that represents the current object. (Inherited from Object.) |
| ::createFromInterface | Creates an instance of the COM class by using the specified COM interface. |
| ::createFromObject | Creates an instance of the COM class by using the specified COM object. |
| ::createFromVariant | Creates an instance of the COM class by using the specified instance of the COMVariant class. |
| ::getObject | Returns an instance of a COM object that is running. |
| ::getObjectEx | Returns an instance of a COM class that is specified by its file name. |
| ::unsupported | Reserved. |
DCOM is also supported by the COM class. DCOM allows for objects that support DCOM to run on remote computers.
When a COM object has been instantiated with the COM class, its methods and properties can be accessed by using either the COMDispFunction class or the extended syntax for the COM class.
The extended syntax allows for methods and properties to be directly called on the COM object, even though they do not appear in the lookup list, such as com.comMethod("Hello World");. The extended syntax supports calls to methods and properties that take any number of arguments.
Some COM objects support the concept of optional arguments. Only optional variant arguments can be omitted. The COM object will then use its default value. To omit an argument for the COM object and force it to use its default value, specify the COMArgument::NoValue enumeration. This is shown in the following example. com.comMethod(COMArgument::NoValue, "Hello Another World"); If the arguments to omit from the COM object are those appearing at the end of the argument list, omit them from the code.
The following types are supported for the extended syntax for the COM class argument type and return type:
-
array
-
COM
-
COMVariant
-
date
-
enum
-
int
-
real
-
str
If a COM object returns a date and the extended syntax is used, the return value of the COM method should be assigned to a COMVariant class variable. The actual date and time (format) can then be extracted from the COMVariant by using the date and time method properties. If the date return value is assigned to a date variable instead of a COMVariant , the time component of the date is lost.
When the extended syntax is used, it is still possible to call the COM class methods, that is the ones that appear in the lookup list, on the objects. The COM class methods have a higher priority than the methods on the actual COM object.
If a method on the COM object has the same name as a method on the COM class, such as attach, call that method cannot be called on the COM object. For Microsoft Dynamics AX to call the method on the COM object instead of the method of the same name on the COM class, prefix the duplicate method name with an underscore, such as com._detach();.
The extended syntax for the COM class is evaluated at run time, not at compile time. This causes a small decrease in performance. If high-performance code is required, consider using the COMDispFunction class . It offers performance improvements compared with the extended syntax for the COM class.
This example calls the GetFileName method from Scripting.FileSystemObject COM object.
void COMExample()
{
COM com;
str result;
InteropPermission perm;
;
// Set code access permission to help protect the use of the
// COM object.
perm = new InteropPermission(InteropKind::ComInterop);
if (perm == null)
{
return;
}
// Permission scope starts here.
perm.assert();
com = new COM("Scripting.FileSystemObject");
if (com != null)
{
result = com.GetFileName(@"c:\boot.ini");
}
// Close code access permission scope.
CodeAccessPermission::revertAssert();
}