为什么在Win环境下使用malloc申请内存总是失败。
如题,请教诸位。
代码如下:
void CTreeListView::ConstrueFilePath(CString &m_InFilePath, CString &m_OutFilePath)
{
CString m_CopyString;
bool IsDIR;
int i,j;
m_CopyString = m_InFilePath.Right(1);
if(m_CopyString.Find('\\') == -1)IsDIR = FALSE;
else
IsDIR = TRUE;
for(j = 0;j<m_InFilePath.GetLength();j++)
{
if(m_InFilePath.GetAt(j) == '\\')break;
}
m_CopyString = m_InFilePath.Left(j);
for(i = 0;(i < TreePoint->number) && (TreePoint->Children[i]->m_FilePath.Compare(m_CopyString) != 0);i++);
if(i>=TreePoint->number)
{
if(IsDIR == TRUE)
{
TreePoint->number++;
TreePoint->Children[i] = (struct TreeStruct *)malloc(sizeof(struct TreeStruct));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`^一到这里就失败,总是返回NULL
TreePoint->Children[i]->hParent = TreePoint->hHandle;
TreePoint->Children[i]->m_FilePath = m_CopyString;
TreePoint->Children[i]->number = 0;
TreePoint = TreePoint->Children[i];
return;
}
else
{
m_OutFilePath = m_CopyString;
return;
}
}
else
{
if(IsDIR ==TRUE)
{
TreePoint = TreePoint->Children[i];
j++;
m_CopyString = m_InFilePath.Mid(j);
m_InFilePath = m_CopyString;
ConstrueFilePath(m_InFilePath,m_OutFilePath);
}
}
}