iCAx开思工具箱

标题: UG二次开发利用极点创建曲线的问题,高手们请进! [打印本页]

作者: abcd8411    时间: 2006-9-4 21:30
标题: UG二次开发利用极点创建曲线的问题,高手们请进!
试编了一小段程序,UG里运行dll时提示:“内存访问冲突”。
请教高手!是什么问题?

#include <uf.h>

#include <uf_ui.h>
#include <uf_curve.h>


#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
#        include <strstream>
#   include <iostream>
#   include <fstream>
#   include <string>

using namespace std;
        using std:strstream;
        using std::endl;        
        using std::ends;
        using std::cerr;
#else
#        include <strstream.h>
#   include <iostream.h>
#endif
#include "curves.h"

//----------------------------------------------------------------------------
//  Activation Methods
//----------------------------------------------------------------------------

//  Explicit Activation
//      This entry point is used to activate the application explicitly, as in
//      "File->Execute UG/Open->User Function..."
extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
    /* Initialize the API environment */

    int errorCode = UF_initialize();

    if ( 0 == errorCode )
    {
   
        /* TODO: Add your application code here */

                /*create a new prt*/
                char part_name[133]="d:\\kk.prt";
                int units=1;
        tag_t part;
        UF_PART_new(part_name,units,&part);

             UF_CURVE_spline_t splinedata;
                tag_p_t splinetag;
                int *num_states;
        UF_CURVE_state_p_t *states=NULL;
splinedata.is_rational=1;
splinedata.num_poles=4;
splinedata.order=3;
splinedata.poles[0][0]=111;
splinedata.poles[0][1]=31;
splinedata.poles[0][2]=46;
splinedata.poles[0][3]=1;
splinedata.poles[1][0]=107;
splinedata.poles[1][1]=46;
splinedata.poles[1][2]=46;
splinedata.poles[1][3]=1;
splinedata.poles[2][0]=98;
splinedata.poles[2][1]=37;
splinedata.poles[2][2]=46;
splinedata.poles[2][3]=1;
splinedata.poles[3][0]=100;
splinedata.poles[3][1]=35;
splinedata.poles[3][2]=46;
splinedata.poles[3][3]=1;
      
               
UF_CURVE_create_spline (&splinedata,splinetag,num_states,states);



    }
        errorCode = UF_terminate();

    /* Print out any error messages */
    PrintErrorMessage( errorCode );
}

//----------------------------------------------------------------------------
//  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 "C" int ufusr_ask_unload( void )
{
    return( UF_UNLOAD_UG_TERMINATE );
}

}
作者: wgwang    时间: 2006-9-5 15:31
内存冲突的原因是你没有给数组分配空间,在splinedata.order=3;后加上这句试试:

splinedata.poles= (double *) UF_allocate_memory( 4*splinedata.num_poles*sizeof(double),&errorcode);




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