You are on page 1of 3

Developing From a Microsoft Visual C++ Project

http://conference.et.byu.edu/~me578/578_shared/NX/1_Intro/Resource...

Developing From a Microsoft Visual C++ Project


The following sections describe how to develop NX4 Open API applications using Microsoft Visual .NET 2003.

Creating a Visual C++ Project


You have two choices for creating a Visual C++ project. You can create a project by using the NX4 Open AppWizard, or by creating a project manually. It is highly recommended that you choose the NX Open AppWizard. It automatically performs all of the steps described in "Creating a NX4 Open Project Manually".

Using the NX4 Open AppWizard


To use the NX4 Open AppWizard: : Step 1 Select the File-->New menu item to activate the New dialog and click the Projects tab. Step 2 Select NX4 Open AppWizard from the list of project types. Step 3 Enter a project name into the "Project name:" text box. By default this becomes the name portion of the program being built. For instance, a project named "MyNXOpenApp" produces either a "MyNXOpenApp.dll" or "MyNXOpenApp.exe". You can override this later if necessary. Step 4 Click "OK" and follow the on-screen instructions to create your NX4 Open project.

Creating a NX4 Open Project Manually


To create a NX4 Open Project manually, you must: create a new project, configure project settings, and add files to the project.

Create a New Project


Step 1 Select one of the following project types: o "Win32 Dynamic-Link Library" for an internal NX4 Open application o "Win32 Console Application" for an external NX4 Open application. Step 2 Configure other options if desired. Step 3 Press the "OK" button to create the project.

Configure Project Settings


Step 1 Configure compile options. o Select the "Project->Settings" menu item to activate the o "Project Settings" dialog and click the "C/C++" tab. o In the "Category:" list box, select "Code Generation". In the "Use run-time library:" list box, select "Multithreaded DLL". Step 2 Configure link options. o Click the "Link" tab on the "Project Settings" dialog. In the "Object/library modules:" text box, add the necessary NX4 libraries. For an Internal mode application, add libufun.lib and libugopenint.lib. For an External mode application add libufun.lib. o Add the libraries identified in the previous step to the "Object/library modules:" text box. o Click the "OK" button. Step 3 Configure the include path. o Select the "Tools->Options" menu item to activate the o "Options" dialog and click the "Directories" tab. o In the "Show directories for:" list box, select "Include files". Add an entry for "%UGII_ROOT_DIR%\ugopen" to the directory list using the proper expansion for the "UGII_ROOT_DIR" environment variable (e.g. C:\ugv160\ugopen). o Use the arrow icon buttons to move the ugopen directory above all other directories. Step 4 Configure the library path. o Select "Library files" in the "Show directories for:" list box of the "Options" dialog.
2010/8/4 08:38

1 of 3

Developing From a Microsoft Visual C++ Project

http://conference.et.byu.edu/~me578/578_shared/NX/1_Intro/Resource...

Add an entry for "%UGII_ROOT_DIR%\ugopen" to the directory list using the proper expansion for the "UGII_ROOT_DIR" environment variable (e.g. C:\ugs160\ugopen). o Use the arrow icon buttons to move the ugopen directory above all other directories. o Click the "OK" button. o

Add Files To The Project


Step 1 Select the "Project->Add To Project->Files" menu item to activate the "Insert Files into Project" dialog. Step 2 Select the files to be added and click the "OK" button.

Debugging and Running


If the project is an internal NX4 Open application (DLL), the following steps must be performed to associate the NX4 executable with the project. If these steps are not performed, the application cannot be executed or debugged from the Visual C++ environment. These steps do not apply to external UG/Open applications (EXEs).

Setup
Step 1 Determine the location of the NX4 executable ugraf.exe. o Go to the Windows "Start" menu and select "Settings->Control Panel". Double-click the "System" icon. Click the "Environment" tab on the resulting "System Properties" dialog. In the "System Variables" list scroll down until you find a variable named "UGII_ROOT_DIR". The value associated with this variable is the directory path to the "ugraf.exe" executable. Select the "UGII_ROOT_DIR" variable. Highlight the complete path in the "Value" field at the bottom of the dialog and copy it to the clipboard. Step 2 Associate the NX4 executable with your project. o From within Visual C++, select the "Project->Settings" menu item and select the "Debug" tab on the resulting "Project Settings" dialog. Notice that the "Executable for debug session:" field is empty. Place the cursor in this field and then type or paste the path determined in the first step, followed by "\ugraf.exe". For example, if the value of "UGII_ROOT_DIR" were "C:\Program Files\UGS\NX4.0\ugii" then you would enter: C:\Program Files\UGS\NX4.0\ugii\ugraf.exe. You may also browse for the executable file by clicking the arrow button to the right of the "Executable for debug session:" field. Step 3 Run the Application o Click "OK" in the "Project Settings" dialog and then run or debug the application as you would normally from Visual C++. NX4 is started each time the project is executed. You are free to place breakpoints in your NX4 Open application just as you would in any other application. It may take a few moments for NX4 to appear because Visual C++ is searching for debug symbols in the NX4 DLLs, so be patient.

Print statements
Since NX4 is a native Windows application, there is no console started up automatically. Therefore using a printf to print to stdout will not work. If you want to use printf or cout statements to debug your internal NX4 Open application, you must add the following code to your internal UG/Open API function: This will create a console window and attach it to stdout so that printf and cout will work.

Known issues
When using NX4 Open, you should not make an MFC extension DLL in debug mode. This is a well known problem with Microsoft compilers. Microsoft uses different libraries for debug and release configurations. NX4 will use a release .dll, and so NX4 Open will allocate memory using the heap in that library. The customer MFC extension DLL in debug mode will use a debug library, and try to free memory using the debug library. The only work around is to either only build a release configuration, or only build as a WIN32 DLL using the NX4 Open AppWizard.

2 of 3

2010/8/4 08:38

Developing From a Microsoft Visual C++ Project

http://conference.et.byu.edu/~me578/578_shared/NX/1_Intro/Resource...

3 of 3

2010/8/4 08:38

You might also like