找回密码 注册 QQ登录
开思网工业级高精度在线3D打印服务

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?在线3D打印服务,一键上传,自动报价 
查看: 17802|回复: 3
打印 上一主题 下一主题

[求助] 二次开发内存访问违例

[复制链接]
跳转到指定楼层
1
发表于 2009-4-16 22:43:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

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;
}
}

本帖最后由 shaoshuailee 于 2009-4-16 22:45 编辑
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 赞一下!赞一下!
2
发表于 2009-4-17 15:34:24 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
3
发表于 2009-4-17 22:12:02 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
4
发表于 2011-4-6 23:12:05 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2024-9-20 15:29 , Processed in 0.023634 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

快速回复 返回顶部 返回列表