// find new size
nNewArraySize = StrNewSizeForCharReplace(pszString, pszFindString, pszReplaceString);

// nNewArry size is 1063

// alllocate memory
pszTemp= (unsigned char*)malloc(nNewArraySize + 1);

// add 1063 character in to pszTEmp

// 1063
nLength = strlen(pszTEmp) // length is 1063

// Heap memory exception

How can remove this exception

why are you calling malloc() is a c++ program? Change it to new and see if that fixes the error. If not, then the real problem is in parts of the program that you did not post.