标题: 二次开发内存访问违例 [打印本页] 作者: shaoshuailee 时间: 2009-4-16 22:43 标题: 二次开发内存访问违例 小弟在做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 );
}