iCAx开思工具箱

标题: 用UG调用.dll文件提示内存访问冲突 [打印本页]

作者: fml2005    时间: 2006-5-2 01:51
标题: 用UG调用.dll文件提示内存访问冲突
我刚学UG OPEN/API没多久,下面这段幼稚的程序是根据一些例子改写的,以Unigraphics NX APPWizard V1做模板。    VC++环境中编译没有问题,可以顺利生成.DLL文件。但是用UG调用会提示内存访问冲突。(调用后可弹出信息窗口,并显示“特征ID:0”)我对VC++不熟,资源分配的东西实在是不懂。希望有高手能指点一二,感激不尽。
tag_t part_id;
tag_t feature;
tag_t attribute;
int type;
int num;
int  fea_id;
char buffer[100]="/0";
char buffe[100]="/0";

part_id=UF_PART_ask_display_part();
type=UF_feature_type;
num=0;
feature=NULL_TAG;

UF_OBJ_cycle_objs_in_part(part_id,type,&feature);

while (feature!=NULL_TAG)
{
        num++;
fea_id= UF_ATTR_ask_part_attribute(&feature);
sprintf(buffer,"特征ID:%s",fea_id);
UF_UI_open_listing_window();
UF_UI_write_listing_window(buffer);
UF_free(buffer);

UF_OBJ_cycle_objs_in_part(part_id,type,&feature);

}

sprintf(buffe,"特征数量:%d",num);
UF_UI_write_listing_window(buffe);
UF_free(buffe);
作者: along533    时间: 2006-5-4 03:50
attribute是个结构体,不能直接赋给buffer.
作者: maomao521    时间: 2006-5-9 11:06
我也遇到一个类似的问题,该程序是通过给定点生成B样条曲面。原来的例子是给定十六个点,我改成了36个点,改了相应得参数,编译连接都没有错误,但是到UG里面执行时出现下面错误,恳请高手指点,
#include <stdio.h>
#include <stdlib.h>
#include <uf.h>
#include <uf_part.h>
#include <uf_defs.h>
#include <uf_obj.h>
#include <uf_modl.h>

#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
static int report( char *file, int line, char *call, int irc)
{
  if (irc)
  {
     char    messg[133];
     printf("%s, line %d:  %s\n", file, line, call);
     (UF_get_fail_message(irc, messg)) ?
       printf("    returned a %d\n", irc) :
       printf("    returned error %d:  %s\n", irc, messg);
  }
  return(irc);
}
static void do_ugopen_api(void)
{
  char    *prtnam = "create_bsurf";
  /* Points for B-surface  */
  double points[36][3] = {
                   0.000000,0.000000,0.005914,
               0.000000,0.200000,0.005074,
               0.000000,0.400000,0.002990,
               0.000000,0.600000,0.001533,
               0.000000,0.800000,0.000828,
               0.000000,1.000000,0.000577,
               0.200000,0.000000,0.003775,
               0.200000,0.200000,0.004451,
               0.200000,0.400000,0.004584,
               0.200000,0.600000,0.005139,
               0.200000,0.800000,0.006252,
               0.200000,1.000000,0.007520,
               0.400000,0.000000,-0.000929,
               0.400000,0.200000,0.001315,
               0.400000,0.400000,0.006451,
               0.400000,0.600000,0.017956,
               0.400000,0.800000,0.038411,
               0.400000,1.000000,0.060684,
               0.600000,0.000000,-0.009034,
               0.600000,0.200000,-0.006401,
               0.600000,0.400000,0.006438,
               0.600000,0.600000,0.041146,
               0.600000,0.800000,0.112490,
               0.600000,1.000000,0.195991,
               0.800000,0.000000,0.008290,
               0.800000,0.200000,0.005289,
               0.800000,0.400000,0.014894,
               0.800000,0.600000,0.031797,
               0.800000,0.800000,0.052069,
               0.800000,1.000000,0.071069,
               1.000000,0.000000,0.159674,
               1.000000,0.200000,0.076535,
               1.000000,0.400000,0.032681,
               1.000000,0.600000,0.013937,
               1.000000,0.800000,0.006826,
               1.000000,1.000000,0.004618,

/*                   3.5, 2.5, 0.0,
                           4.0, 2.6, 0.2,
                           4.5, 2.6, 0.2,
                           5.0, 2.5, 0.0,
                           3.3, 3.0, 0.2,
                           4.1, 3.2, 0.3,
                           4.5, 3.2, 0.3,
                           5.0, 3.0, 0.2,
                           3.0, 3.5, 0.2,
                           3.8, 3.6, 0.3,
                           4.5, 3.6, 0.3,
                           5.0, 3.5, 0.2,
                           2.6, 4.0, 0.0,
                           3.3, 4.0, 0.2,
                           4.5, 4.0, 0.2,
                           5.0, 4.0, 0.0 */
                           };       

  int create_mode = 1;
  int u_closed_status = 0;
  int v_closed_status = 0;
  int u_degree = 3;
  int v_degree = 3;
  int num_rows = 6;
  int pts_per_row[6] = {6, 6, 6, 6};
  int ii, jj, kk, indx;
  tag_t   part_tag;
  tag_t   bsurf_obj_id = NULL_TAG;
  UF_MODL_bsurf_row_info_t *pts_info_per_row; /* pts info for each row */
  UF_MODL_bsurface_t   bsurf;
  /* Open a new part */
  UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) );
  pts_info_per_row = ( UF_MODL_bsurf_row_info_t *)malloc( num_rows *
                       sizeof(UF_MODL_bsurf_row_info_t) );
  /* allocate and load point and other information for each row of points */
  indx = 0;
  for (ii=0; ii<num_rows; ii++)
  {
    pts_info_per_row[ii].num_points = pts_per_row[ii];  /* can vary */
    pts_info_per_row[ii].points = (double *)malloc( pts_per_row[ii] * 3 *
                                   sizeof(double) );
    pts_info_per_row[ii].weight = (double *)malloc( pts_per_row[ii] *
                                   sizeof(double) );
    /* load up point and weight info */
    for (jj=0, kk = 0; kk<pts_per_row[ii]; kk++, jj+=3, indx++)
    {
      pts_info_per_row[ii].points[jj] = points[indx][0];
      pts_info_per_row[ii].points[jj+1] = points[indx][1];
      pts_info_per_row[ii].points[jj+2] = points[indx][2];
      pts_info_per_row[ii].weight[kk] = 1.0;
    }
  }
  /* create B-surface */
  UF_CALL(UF_MODL_create_bsurf_thru_pts( create_mode, u_closed_status,
                                         v_closed_status, u_degree,
                                         v_degree, num_rows, pts_info_per_row,
                                         &bsurf_obj_id));
                   
  if ( bsurf_obj_id == NULL_TAG )
    printf("*** ERROR CREATING B-SURFACE ***\n");

  /* free allocated memory */
  for (ii=0; ii<num_rows; ii++)
  {
    free(pts_info_per_row[ii].points);
    free(pts_info_per_row[ii].weight);
  }
  free(pts_info_per_row);
  /* ask the B-surface information */
  UF_CALL(UF_MODL_ask_bsurf( bsurf_obj_id, &bsurf ));
  
  /* validate the surface */
  if ( (bsurf.order_u != u_degree+1) || (bsurf.order_v != v_degree+1) )
    printf("*** ERROR ASKING B-SURFACE ***\n");
  
  UF_CALL(UF_MODL_free_bsurf_data(&bsurf));
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int param_len)
{
  if (!UF_CALL(UF_initialize()))
  {
    do_ugopen_api();
    UF_CALL(UF_terminate());
  }
}
int ufusr_ask_unload(void)
{
  return (UF_UNLOAD_IMMEDIATELY);
}
作者: halm    时间: 2006-5-9 15:14
u_degree 参数不对




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