我的c++程序之前在vc++6.0环境下运行正常,现在在VS2010下调试出现错误:HEAP CORRUPTION DETECTED......,经查询,可能是在Myfile.cpp中使用了new.delete申请了内存空间,导致内存操作越界,在该程序段加了 ASSERT(_CrtCheckMemory())后没有出现那个错误提示,但运行后对话框窗口不见了,实际上不能成功,由于我是新手,初次到CSDN中来求助,还望前辈高手不吝赐教,小弟万分感谢。其中的部分代码如下:
int ChangeNameExtension( CString s1)
{
int i,j;
char *ExtendedName;
USES_CONVERSION;
int n = s1.GetLength();
char *temp = new char(n*2+1);
strcpy(temp,(LPCTSTR)s1);
if ((ExtendedName=strchr(temp,'.'))==NULL)
{
//AfxMessageBox("文件扩展名有误!");
return -1;
}
ExtendedName++;
return 0;
}
int ChangeFileName( CString s1)//return:-1, 0, 1
{
int i,j;
char *ExtendedName;
USES_CONVERSION;
int n = s1.GetLength();
char *temp = new char(n*2+1);
strcpy(temp,(LPCTSTR)s1);
// ASSERT(_CrtCheckMemory());
if ((ExtendedName=strchr(temp,'.'))==NULL)
{
//AfxMessageBox("文件扩展名有误!");
delete[] temp;
return -1;
}
ExtendedName--;
//判断文件名是否符合递增要求,即是否有数字。
if (*ExtendedName<'0' || *ExtendedName>'9')
{
delete[] temp;
return -1;
}
for(i=0;i<=ExtendedName-s1;i++)
if(*(ExtendedName-i)<'9')
{
(*(ExtendedName-i))++;
j = i - 1;
while(j>=0)
{
(*(ExtendedName-j)) = '0';
j--;
}
delete[] temp;
return 1;
}
delete[] temp;
return 0;
}