所以我遇到了堆问题的损坏,想知道它是否与我如何处理某些数组有关。实际上,在某些时候,我有一些这样的消息发送到我的 WinProc:
SendMessage(hwnd, LOG_ADD, NULL, (LPARAM)L"Initializing winsock... ");
LOG_ADD 定义为 104。在 WinProc 内部,当 msg==LOG_ADD 时,会发生以下情况:
case LOG_ADD:
{
pGame->pMessageLog->PutToLog((WCHAR*)lParam);
pGame->pD2DResources->OnRender(pGame->pMessageLog);
有 MessageLog::PutToLog(WCHAR[]):
void MessageLog::PutToLog(WCHAR txt[])
{
int strLen=wcslen(txt);
int logLen=wcslen(logHistory);
WCHAR* pWCHAR = txt;
int x=0;
// Counts the number of '\n' into wString and adds that number to nLogLines
for(x=0; x<strLen; x++)
{
if(pWCHAR[x]=='\n')
nLogLines++;
}
pWCHAR = logHistory;
x=0;
while(nLogLines>5)
{
if(pWCHAR[x]=='\n')
nLogLines--;
x++;
}
if(x!=0)
{
for(int y=0; y<logLen-x; y++)
{
pWCHAR[y]=pWCHAR[y+x];
}
}
wcscat (logHistory, txt);
}
这能解释腐败问题吗?实际上,当我删除所有 SendMessage(hwnd, LOG_ADD...) 行时,当编译器执行“struct hostent* host;”行时,损坏不会在几行后出现。或“如果((主机=gethostbyname(服务器))==NULL)”。