iCAx开思工具箱

标题: 【资料】给像我这样的入门者 [打印本页]

作者: liberty000    时间: 2004-4-21 21:53
标题: 【资料】给像我这样的入门者
虽然是从UG Documentation里摘录的,但初学者不易找到,希望对大家有点用!大家注意:下面的VC虽然它说是7.0版本,可实际上它讲的设置都是6.0的。
  
This section begins the machine specific information for setting up Open C API on a Windows NT Operating System and includes the necessary information you need to create environment variables, compile, link, and run your Open C API programs.  
NOTE: Unigraphics does not support the use of FORTRAN in Open C API programs in the Windows NT Operating System environment.  
This section describes the variable you need to define for Open C API. We list the variable and its description in the following table.  
Variables  and their Description
UGII_USERFCN :This variable points to the directory where the   Open C API libraries reside. You can define this variable by executing the script %UGII_BASE_DIR%\ugopen\ufvars.bat.
CL:This system environment variable is used to pass default options to the MSVC++ compiler. The ufvars.bat script initialized this variable with options needed for Open C API compiles.
INCLUDE:This system environment variable is used to enable the C preprocessor to locate headers (.h files). The ufvars.bat script modifies this variable to incorporate the location of the Open C API headers.
LIB:This system environment variable is used to enable the linker to locate object libraries and import libraries. The ufvars.bat script modifies this variable to incorporate the location of the Open C API import libraries, libufun.lib and libugopenint.lib.
PATH:This system environment variable is used to enable the system to locate executables, DLL's and scripts. The ufvars.bat script modifies this variable to enable easy access to the uflink.bat script.
Open C API Modes, Functions, and User Exits
The following paragraphs provide descriptions of these items with respect to the Windows NT Operating System.  
External Open C API programs are executable images (.exe) that run and can access the Unigraphics database without bringing up interactive Unigraphics. These are programs which make reference to Open C API entry points in the dynamic link library libufun.dll. This dll must be accessible at run-time. Normally Unigraphics dlls are found in a directory in the user's %PATH% variable, which is configured by the Unigraphics installation. An external Open C API program is linked with an import library, libufun.lib, which specifies all of the available entry points in libufun.dll. This import library is located in the %UGII_BASE_DIR%\ugopen directory and is not required at run-time.  
Internal Open C API programs are implemented as dlls which themselves are loaded by Unigraphics at runtime. It is necessary for the Internal Open C API programs to include uf.h to obtain the function prototype for ufusr in order that it be properly exported from the user's dll. Otherwise your program may link but will not run due to the missing entry point.  
User Exits are programs that are also implemented as dlls which are loaded by Unigraphics at runtime. As on Unix platforms the location of the user's program is specified by an environment variable which implies when it should be invoked and the name of the entry point to be executed. It is necessary to include uf_exit.h to obtain the function prototypes for the various User Exit functions.  
The available entry points in libufun.dll and libugopenint.dll are limited to the published interface for External Open C API and Internal Open C API, respectively.  
Developing From a Microsoft Visual C++ Project
The following sections describe how to develop Open C API applications using Microsoft Visual C++ 7.0. It is recommended that all Open C program development on Windows NT be down from a Visual C++ project.
Starting Visual C++   
You can start Visual C++ via the icon in the Start menu or by typing "msdev.exe" at a command prompt.  
Creating a Visual C++ Project   
You have two choices for creating a Visual C++ project. You can create a project by using the Open C AppWizard, or by creating a project manually. It is highly recommended that you choose the Open C AppWizard. It automatically performs all of the steps described in "Creating an Open C Project Manually".  
Using the Open C AppWizard   
To use the Open C AppWizard:  
Step 1 Select the File-->New menu item to activate the New dialog and click the Projects tab.  
Step 2 Select Open C AppWizard from the list of project types.  
Step 3 Enter a project name into the "roject name:" text box. By default this becomes the name portion of the program being built. For instance, a project named "MyUGOpenApp" produces either a "MyUGOpenApp.dll" or "MyUGOpenApp.exe". You can override this later if necessary.  
Step 4 Click "OK" and follow the on-screen instructions to create your Open C project.  
Creating a Open C Project Manually   
To create an Open C Project manually, you must: create a new project, configure project settings, and add files to the project. The details follow.  
Create a New Project  
Step 1 Select one of the following project types:  
"Win32 Dynamic-Link Library" for an internal Open C application  
"Win32 Console Application" for an external Open C 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.  
Select the "roject->Settings" menu item to activate the  
"roject Settings" dialog and click the "C/C++" tab.  
In the "Category:" list box, select "Code Generation". In the "Use run-time library:" list box, select "Multithreaded DLL".  
Step 2 Configure link options.  
Click the "Link" tab on the "roject Settings" dialog. In the "Object/library modules:" text box, add the necessary Unigraphics libraries. For an Internal mode application, add libufun.lib and libugopenint.lib. For an External mode application add libufun.lib.  
Add the libraries identified in the previous step to the "Object/library modules:" text box.  
Click the "OK" button.  
Step 3 Configure the include path.  
Select the "Tools->Options" menu item to activate the  
"Options" dialog and click the "Directories" tab.  
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).  
Use the arrow icon buttons to move the ugopen directory above all other directories.  
Step 4 Configure the library path.  
Select "Library files" in the "Show directories for:" list box of the "Options" dialog.  
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).  
Use the arrow icon buttons to move the ugopen directory above all other directories.  
Click the "OK" button.  
Add Files To The Project  
Step 1 Select the "roject->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.  
Compiling and Linking   
Select the "build" icon or press the "F7" function key to build the project. Projects created using the Open C AppWizard compile and run "as-is".  
Debugging and Running
If the project is an internal Open C application (DLL), the following steps must be performed to associate the Unigraphics 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 Open C applications (EXEs).  
Step 1 Determine the location of the Unigraphics executable ugraf.exe.  
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 Unigraphics executable with your project.  
From within Visual C++, select the "roject->Settings" menu item and select the "Debug" tab on the resulting "roject 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:\ugs160\ugii" then you would enter: C:\ugs160\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 Set the working directory.  
The "Working directory:" field on the "roject Settings" dialog specifies the directory from which Visual C++ runs Unigraphics. A common convention is to use "C:\TEMP" for the working directory.  
Step 4 Set the Unigraphics program arguments (optional)  
You may set any Unigraphics program arguments you require by entering them in the "rogram arguments:" field on the "roject Settings" dialog. The syntax is exactly the same as the command-line syntax for starting Unigraphics.
Step 6 Run the Application  
Click "OK" in the "Project Settings" dialog and then run or debug the application as you would normally from Visual C++. Unigraphics is started each time the project is executed. You are free to place breakpoints in your Open C application just as you would in any other application. It may take a few moments for Unigraphics to appear because Visual C++ is searching for debug symbols in the Unigraphics DLLs, so be patient.  
Print statements
Since Unigraphics 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 statements to debug your internal Open C application, you must add the following code to your internal Open C API function:  
#include <windows.h>
#include <fstream.h>
#include <stdio.h>
...
FILE *fp;
...
  
/* allocate console window conout$ */
AllocConsole();
/* reopen stdout on conout$ for fprintf and printf */
fp = freopen("conout$", "w", stdout);
This will create a console window and attach it to stdout so that printf and fprintf will work.
Known issues
When using Open C++, you should not make an MFC extension DLL in debug mode.  
This is a well known problem with Microsoft compilers. Microsoft uses different libraries fro debug and release configurations. Unigraphics will use a release .dll, and so Open C++ 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 Open C AppWizard.
Running Open C API Programs
Open C API programs can be run from any of four environments:  
[$#8226]  Microsoft Visual C++  
[$#8226]  A console window, such as that created by the "UG Command Prompt" menu item  
[$#8226]  An interactive Unigraphics session  
[$#8226]  A Unigraphics GRIP program
To run an External application, select "Execute" from Visual C++ or type the name of the application at a shell prompt. When executing from the command line, the dynamic link library libufun.dll must be accessible using the normal search rules that the Windows NT operating system uses to find a DLL. Typically, libufun.dll is found in the directory specified by the UGII_ROOT_DIR environment variable, which should be included in your PATH environment variable.  
To run an Internal application from Visual C++, follow the "Debugging" setup instructions under "Developing from a Microsoft Visual C++ Project". To run an Internal application from within Unigraphics, use the "File->Execute Open C->User Function..." menu, which displays a file selection dialog that allows you to browse for your application. When you have selected a program, Unigraphics attempts to load the DLL and call the "ufusr" entry point. If the DLL cannot be loaded or the entry point cannot be called, an error message is displayed.  
Error Messages
When setting up the execution of an Internal Open C API program, the following error messages can occur:  
1. "FILE NOT FOUND" (several) ugraf: unresolved references -- ufxxxx ugraf can't continue.
Possible cause: The program linked as an Internal Open C API program, but which does NOT have the required UFUSR Entry Point.  
2. "LIBRARY IS MISSING REQUIRED ENTRY POINT" This can occur if an Internal Open C API program or User Exit does not contain the expected entry point, such as ufusr or ufsta. To determine the entry points in a dll, use the dumpbin utility supplied with msvc++. For example:
dumpbin -exports myuserxit.dll  
Possible cause: If the proper header files (e.g. uf.h for ufusr or uf_exit.h for User Exits) are not used, then the compiler can not see the dllexport attribute of the function prototype and does not know that the function is to be exported from the dll.
作者: goodluckwu    时间: 2004-4-23 15:43
最近一直扎在日文资料里,看英语倍感亲切,可是暂时还是没有时间和耐心把这么长的英文看完
作者: fourwood_0328    时间: 2004-4-27 15:33
那怎么多啊,UG二次开发不就是VC下面的DLL动态连接库开发吗?随便找本VC教程找到DLL相关内容看看不就可以,还看什么英文啊。




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3