1.19.2 Access an External Application

The Microsoft Component Object Model (COM) is a software architecture that allows applications to be built from a binary software component, and it makes the development of software much easier and more effective.

Origin provides the capability for COM client programming, and it is supported only in OriginPro. This mechanism uses Object type to represent all COM (automation server) objects. All COM objects can be initialized in two ways:

//by the CreateObject method
Object oExcel;
oExcel = CreateObject("Excel.Application");

//by initialization from an existing COM object. 
Object oWorkBooks;
oWorkBooks = oExcel.Workbooks;

Origin C also provides a class to access Matlab, which enables communication between Origin and Matlab.

#include <Origin.h>
#include <externApps.h> //required header for the MATLAB class
void test_Matlab()
    Matlab matlabObj(true);
        out_str("No MATLAB found");
    //defines 3x5 matrix named ma
    string strRet;
    strRet = matlabObj.Execute("ma=[1 2 3 4 5; 
        4 5 6 7 8;10.3 4.5 -4.7 -23.2 -6.7]"); 
    out_str(strRet);// show str from MATLAB
    // put matrix into Origin matrix
    MatrixLayer matLayer;
    Matrix mao(matLayer);
    //Transfer MATLAB's matrix (ma) to Origin's mao matrix.
    BOOL bRet = matlabObj.GetMatrix("ma", &mao);

COM client programming in Origin C can be used to programmatically exchange data with MS Office applications. There is a comprehensive example demonstrating how to read data from Excel worksheets, plot a graph in Origin, and place it in a Word document. This example can be found in the \Samples\COM Server and Client\MS Office\Client subfolder in Origin.

(Origin C COM programming can also be used to communicate with databases by accessing an ActiveX Data Object (ADO), and there is a sample file demonstrating that SQL and Access databases can be imported to a worksheet, and subsequent data modifications returned to the database. For more information, see the file ADOSample.c in the Samples\COM Server and Client\ADO\Client subfolder of Origin.