我写了个DLL用来读取Excel表格数据,在DLL里定义了一个函数
GetStandardPartInfo(int &iCount,PartInfo (&sPt)[1024]);
其中PartInfo是个自定义结构,包含四个string类型的成员。该函数中
有段代码如下所示:
CString tempCStr;
iCount=staPartInfoVec.size();
for(int i=0;i<iCount;i++)
{
tempCStr=staPartInfoVec[i].Hosize;
sPt[i].Hosize=LPCTSTR( tempCStr);
tempCStr=staPartInfoVec[i].HosizeToler;
sPt[i].HosizeToler=LPCTSTR( tempCStr);
tempCStr=staPartInfoVec[i].PartName;
sPt[i].PartName=LPCTSTR( tempCStr);
tempCStr=staPartInfoVec[i].PartNum;
sPt[i].PartNum=LPCTSTR( tempCStr);
}
然后再主程序里面的调用代码如下:
struct PartInfo sPt[1024];
int iCount=0;
GetStandardPartInfo(iCount,sPt]);
运行结果就是会存在内存泄露问题,而且这个问题时隐时现,
请问各位存在,结构体数组怎样才能正确传参而不会产生内
存泄露?我上面的写法是否有什么问题?