|
马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
小弟在做ug二次开发的毕设,想通过单击菜单后自动打开一个预先画好的零件,该零件放在prt_file文件下,生成的open_part.dll文件不知道是什么问题,只要把该dll文件放到startup下面,再单击菜单ug就会出现内存访问违例,这个错误,可是若把open_part.dll放到其他位置,通过Ctrl+u就没问题。网上查了一下说“内存访问违例”的原因可能是指针的问题,可是我源程序也找不出是什么问题,求大侠帮忙啊!不胜感激~~~~~~~~~
程序如下:
/*****************************************************************************
**
** open_part.cpp
**
** Description:
** Contains Unigraphics entry points for the application.
**
*****************************************************************************/
/* Include files */
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
# include <strstream>
# include <iostream>
using std:strstream;
using std::endl;
using std::ends;
using std::cerr;
#else
# include <strstream.h>
# include <iostream.h>
#endif
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <uf_mb.h>
#include <uf_studio.h>
#include <uf_part.h>
#include <uf_styler.h>
#include <uf_defs.h>
#include <stdio.h>
#include "open_part.h"
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
static int report_error(char *file, int line, char *call, int irc)
{
if (irc)
{
char err[133],
msg[133];
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
irc, line, file);
UF_get_fail_message(irc, err);
UF_print_syslog(msg, FALSE);
UF_print_syslog(err, FALSE);
UF_print_syslog("\n", FALSE);
UF_print_syslog(call, FALSE);
UF_print_syslog(";\n", FALSE);
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n");
}
}
return(irc);
}
int open_in_part();
/*****************************************************************************
** Activation Methods
*****************************************************************************/
/* Unigraphics Startup
** This entry point activates the application at Unigraphics startup */
extern DllExport void ufsta( char *param, int *returnCode, int rlen )
{
/* Initialize the API environment */
UF_MB_cb_status_t FoundationPart(UF_MB_widget_t,UF_MB_data_t,UF_MB_activated_button_p_t);
//声明一个激活应用的列表结构,该结构实例与用户菜单文件中激活的应用相匹配,此处的结构实例为FOUNDATION_PART
static UF_MB_action_t action_table[] = {
{"FOUNDATION_PART",FoundationPart,NULL},
{NULL,NULL,NULL}
};
//下列表达式等效于if(UF_CALL(UF_initialize())!=0),完成初始化
if( UF_CALL(UF_initialize()) )
{
/* Failed to initialize */
return;
}
/* TODO: Add your application code here */
int error_code = 0;
//注册UG应用或叫做通过触发菜单命令激活用户的应用
if ((error_code = UF_MB_add_actions(action_table))!=0)
{
char fails_message[133];
/*get the user function fail message based on the fail code*/
UF_get_fail_message(error_code,fails_message);//返回与错误代码有关的消息串
UF_UI_set_status(fails_message);
printf("%s\n",error_code);
}
open_in_part();
/* Terminate the API environment */
UF_CALL(UF_terminate());
return;
}
/*****************************************************************************
** Utilities
*****************************************************************************/
/* Unload Handler
** This function specifies when to unload your application from Unigraphics.
** If your application registers a callback (from a MenuScript item or a
** User Defined Object for example), this function MUST return
** "UF_UNLOAD_UG_TERMINATE". */
extern int ufusr_ask_unload( void )
{
return( UF_UNLOAD_UG_TERMINATE );
}
//主函数FoundationPart定义如下
static UF_MB_cb_status_t FoundationPart(
UF_MB_widget_t widget, //trigger widget
UF_MB_data_t client_data, //data pointer from action registration
UF_MB_activated_button_p_t button)
{
UF_initialize();
int resp;
resp = open_in_part();
if (resp!=0)
{
uc1601("在零件环境下打开标准件失败",1);
return UF_MB_CB_CONTINUE;
}
return UF_MB_CB_CONTINUE;
UF_terminate();
}
int open_in_part()
{
char *ptr;
char part_name[100];
tag_t part_tag;
UF_PART_load_status_t error_status;
int err;
char err1[2] = " ";
UF_translate_variable("UGII_STANDARD_PATH",&ptr);
if (ptr == NULL)
{
uc1601("环境变量UGII_STANDARD_PATH不存在",1);
//return 1;
}
strcpy(part_name,ptr);
strcat(part_name,"\\foundation_part.prt");
uc1601(part_name,1);
err = UF_PART_open(part_name,&part_tag,&error_status);
err1[0] = err;
uc1601(err1,1);
//UF_CALL(err);
UF_PART_free_load_status(&error_status);
if (part_tag==NULL_TAG)
{
uc1601("没有提取出零件",1);
return 1;
}
if (err == 0)
{
uc1601("打开零件成功",1);
return 0;
}
if (err !=0)
{
uc1601("打开零件失败!",1);
return 1;
}
}
|
|