次の方法で共有


COM.getObject(String) Method

Definition

Returns an instance of a COM object that is running.

public:
 static Dynamics::AX::Application::COM ^ getObject(System::String ^ _className);
public static Dynamics.AX.Application.COM getObject (string _className);
static member getObject : string -> Dynamics.AX.Application.COM
Public Shared Function getObject (_className As String) As COM

Parameters

_className
String

The ProgID value or class name of the COM object that is used to create the instance of the COM class.

Returns

COM

An instance of the COM class for the class that is specified by the className parameter; nullNothingnullptrunita null reference (Nothing in Visual Basic) if the instance could not be created.

Remarks

If multiple instances of the specified COM object are running, we cannot guarantee which instance will be returned by the getObject method. Some COM objects do not support the extended features that enable calls to this method.

The following example shows how to retrieve an instance of a running COM object.

COM objExcel, objWorkBook, objWorkBooks; 
InteropPermission perm; 
// Set code access permission to help protect the use of COM.new. 
perm = new InteropPermission(InteropKind::ComInterop); 
perm.assert(); 
objExcel = COM::getObject("Excel.Application"); 
if (!objExcel) 
{ 
    // Unable to connect to a running instance of Microsoft Excel. 
    // Try starting it. 
    objExcel = new COM("Excel.Application"); 
    if (!objExcel) 
    { 
        Info ("Unable to find or create an instance of Excel"); 
        return;  // Or other error action. 
    }  
} 
// Close code access permission scope. 
CodeAccessPermission::revertAssert(); 
objExcel.visible(true); 
objWorkBooks = objExcel.workbooks(); 
if (objWorkBooks) 
{ 
    objWorkBook = objWorkBooks.open("d:\mydata\book1.xls"); 
}

Applies to