As Cimatron E API uses the COM based approach, there are several ways to start working with it. One of the most convenient ways is to use the #import directive in Visual C++. All examples in the help documentation use this approach to work with API.
The compiler directive #import generates a _com_ptr_t template class for each interface. An object of this class encapsulates a COM interface pointer and is called a "smart" pointer. This template class manages resource allocation and deallocation, via function calls to the IUnknown member functions and automates the required calls to the AddRef, Release, and QueryInterface functions.
Using this approach simplifies the work with COM objects and error checking. If an error occurs, the system generates a _com_error object that represents an exception condition and contains all information provided by the COM object about the error, the HRESULT error code and any associated IErrorInfo object.
For more information about Compiler COM Support Classes, please see the MSDN documentation.
Cimatron E API uses the hierarchical object model. This means that if an object stays at the top of the hierarchy, other objects are derived from it.
These kinds of objects are the Application objects of Cimatron E API.
To get an Application object of a running active Cimatron E application, use the AppAccess object. This object is created by calling the CoCreateInstance method in a user application. Its interface (IAppAccess) allows you to connect to a running active Cimatron E application by returning a pointer to the IApplication interface of the Application object.
If there is no running Cimatron E application or you want to start a new one, you have to create an instance of the Application object by calling the CoCreateInstance method in a user application and receive a pointer to the IApplication interface.
Once you have a pointer to the IApplication interface, you can start to execute a task of your user application.
There is no any special requirement for the type of project you can create in Visual C++.
To start using API in your C++ application you have to:
Import the necessary type libraries using the #import directive. An alternative way is to use the CimAPIinc.h header file. This file is coded so that it excludes any redefinitions of interfaces that occur in other Cimatron E API type libraries. This file creates the CimAPI namespace that encapsulates all Cimatron E API interfaces.
After importing the type libraries you have definitions of all API interfaces. The next step is to get an IApplication interface.
CimAPI::IApplicationPtr gCimApp = NULL; //Cimatron E Application
CimAPI::IAppAccessPtr aAppAccess; //An application access helper object
CoInitialize( NULL );
aAppAccess.CreateInstance( __uuidof( CimAPI::AppAccess ), NULL, CLSCTX_ALL );
if(aAppAccess == NULL) {
AfxMessageBox("Unable to create AppAccess object");
exit(1);
}
gCimApp = aAppAccess->GetApplication( );
if( gCimApp == NULL ) {
gCimApp.CreateInstance( __uuidof( CimAPI::Application ), NULL, CLSCTX_ALL ); //Creating new instance of Cimatron E Application object
}
Now you are ready to use the power of Cimatron E API.