Fatal Error when using my function

Fatal Error when using my function

Anonymous
Not applicable
275 Views
0 Replies
Message 1 of 1

Fatal Error when using my function

Anonymous
Not applicable
Hello all

I had created a function to read the xdata of an object
passing its objectid.

everthing works fine but when i am using it continuosly it
gives me fatal error. What could be the problem with the function.

Posting my functions below.
Thanks
Sri

STDMETHODIMP rgs::getxdata(LONG objid, BSTR appname, LONG pos, BSTR *output)
{
AcApDocument* pDoc = acDocManager->curDocument();
if ( acDocManager->lockDocument(pDoc) == Acad::eOk)
{
AcDbObject * pEnt = NULL;
AcDbObjectId * pObjID = new AcDbObjectId();
pObjID->setFromOldId(objid);
if ( acdbOpenObject( pEnt, *pObjID, AcDb::kForRead, Adesk::kTrue ) == Acad::eOk )
{
struct resbuf *pRb;
char* dtype;
char* app;
char* str1;
char* str2;
char* str3;
char* str4;
char* str5;
char* str6;
app="Sample";
pRb = pEnt->xData(app);

if (pRb != NULL)
{
dtype= getxd (pRb,1);
if (strcmp (dtype,"RA") == 0)
{
str1= getxd (pRb,6);
str2= ";RA";
str3= "";
str4= "";
str5= "";
str6= "";
dtype=strcat(str1,str2);
}

if (strcmp (dtype,"CA") == 0)
{
str1= strcat(getxd (pRb,31),";");
str2= strcat(str1,getxd (pRb,32));
str3= strcat(str2,";");
str3= strcat(str3,getxd (pRb,33));
str4= strcat(str3,";");
str4= strcat(str4,getxd (pRb,34));
str5= strcat(str4,";");
str5= strcat(str5,getxd (pRb,35));
str5= strcat(str5,";");
str6= strcat(str5,getxd (pRb,36));

dtype=strcat(str2,";CA");
}
if (dtype != NULL)
{
_bstr_t bstr = dtype;
*output=bstr;
free(output);
}

free(str1);
free(str2);
free(str3);
free(str4);
free(str5);
free(str6);
free(dtype);
}
acutRelRb(pRb);
pEnt->close();
free(app);
}

delete pObjID;

SysFreeString(appname);
acDocManager->unlockDocument(pDoc);
}
return S_OK;
}


char* getxd(struct resbuf* pRb, int pos)
{
int rt, i;
char *return_val;
char hexstring[10];
int decimal,sign;

return_val="";
for (i = 0;pRb != NULL;i++, pRb = pRb->rbnext)
{
if (i == pos)
{
if (pRb->restype < 1010)
{
rt = RTSTR;
}
else if (pRb->restype < 1040)
{
rt = RT3DPOINT;
}
else if (pRb->restype < 1060)
{
rt = RTREAL;
}
else if (pRb->restype < 1071)
{
rt = RTSHORT;
}
else if (pRb->restype == 1071)
{
rt = RTLONG;
}
else
{// restype is already RTSHORT, RTSTR,...
rt = pRb->restype; // or else it is unknown.
}

switch (rt)
{
case RTSHORT:
//acedAlert("1");
return_val= itoa(pRb->resval.rint,hexstring,16);
break;
case RTREAL:
//acedAlert("2");
return_val = _ecvt(pRb->resval.rreal,15,&decimal,&sign);
break;
case RTSTR:
//acedAlert("3");
return_val = pRb->resval.rstring;
break;
case RTLONG:
//acedAlert("4");
return_val = _ecvt(pRb->resval.rlong,15,&decimal,&sign);
break;
}
}

}

//acutRelRb(pRb);
return return_val;
free(pRb);
}
0 Likes
276 Views
0 Replies
Replies (0)