Overview
The STEP-NC DLL is a .NET API that can be used from C#, Visual Basic, or C++ through Windows Common Language Infrastructure (CLI) calls. The DLL also exports a COM version of API for use with C++ applications that can not use CLI to call the .NET functions.
Registering the COM Interface
The COM interface must be manually registered before using the COM interface. Manually run regasm from an administrator shell.
# if you are registering the 64bit DLL c:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe \If you would like to clear all COM registration, use this .reg file.c:\Program Files (x86)\STEP Tools\STEP-NC Machine\stepnc_x64.dll# if you are registering the 32bit DLL c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exec:\Program Files (x86)\STEP Tools\STEP-NC Machine\stepnc_x32.dll
Sample Program Using COM
It is likely that you are using COM because you are adding functionality to an existing project. If you are creating a new project, however, there are no special settings to be aware of. Any plain C++ Win32 application will work just fine. Try it with the sample project containing a COM version of the STEP-NC Hello World example. The source code is shown below.
The #import statements at the top of the program bring in the type library definitions for the core Microsoft classes, and either the 32bit or 64bit version of the STEP-NC DLL. The type library files are located in the STEP-NC Machine install directory.
Further down, the program initializes COM, creates a smart pointer class, and then makes normal calls. The smart pointer class for AptStepMaker is _AptStepMakerPtr, for Finder it is _FinderPtr, and for Tolerance it is _TolerancePtr.
#include <comutil.h> #include <stdio.h> #import <mscorlib.tlb> #import <System.tlb> // The namespace and TBL files are different depending on whether you // are using the 32bit or 64bit version of the library. The calls are // otherwise the same. #ifdef _WIN64 #importc:\\Program Files (x86)\\STEP Tools\\STEP-NC Machine\\stepnc_x64.tlb#define STEPNC_NAMESPACE stepnc_x64 using namespace stepnc_x64; #else #importc:\\Program Files (x86)\\STEP Tools\\STEP-NC Machine\\stepnc_x86.tlb#define STEPNC_NAMESPACE stepnc_x86 using namespace stepnc_x86; #endif using namespace std; // This example uses the COM Smart pointers, which have an underscore // prefix and "Ptr" suffix. You can also do it the old-school way // using CoCreateInstance _AptStepMakerPtr oApt; int main(int argc, char* argv[]) { // Initialize COM. HRESULT hr = CoInitialize(NULL); if (!SUCCEEDED (hr)) { printf(Could not initialize COM\n); return 1; } // This how smart pointers create the instance hr = oApt.CreateInstance(__uuidof(AptStepMaker)); if (!SUCCEEDED (hr)) { printf(Could not initialize Apt instance\n); return 1; } // Create a trivial STEP-NC file oApt->PartNo (test part); oApt->DefineTool (0.25, 5.0, 1.0, 2.0, 3.0, 4.0, 5.0); oApt->LoadTool (1); oApt->Rapid (); oApt->GoToXYZ (point001, 1.0, 12.0, 0.0); oApt->GoToXYZ (point002, 1.0, 14.0, 0.0); oApt->SaveAsModules (test); // Clean up when finished with COM CoUninitialize(); return 0; }