Something wrong either with lParam or with WCHAR[] <p>First, this function is called many times. It should be noted that wString[] does contain the character constant '\n'.</p> <pre><code>void D2DResources::PutToLog(WCHAR wString[]) { int strLen=wcslen(wString); int logLen=wcslen(log); if(strLen+logLen&gt;=MaxLogSize) wcsncpy(log, log, logLen-strLen); wcscat (log, wString); int nLines=0; for(int x=0; x&lt;wcslen(log); x++) { if(log[x]=='\n') { nLines++; if(nLines&gt;5) { log[x]='\0'; } } } SendMessage (m_hWnd, WM_PAINT, NULL, (LPARAM)nLines); } </code></pre> <p>At the end, a WM_PAINT message is sent while nLines should be non-zero since log contains multiples '\n'. My WndProc receives the message and processes it.</p> <pre><code>case WM_PAINT: { pD2DResources-&gt;OnRender((int)lParam); ValidateRect(hWnd, NULL); } break; </code></pre> <p>After which OnRender is called with a (supposedly) non-zero int as an lParam.</p> <pre><code>void D2DResources::OnRender(int nLogLines) { D2D1_SIZE_F screenSize = pCurrentScreen-&gt;GetSize(); D2D1_SIZE_F rTSize = pRT-&gt;GetSize(); pRT-&gt;BeginDraw(); pRT-&gt;DrawBitmap( pCurrentScreen, D2D1::RectF(0.0f, 0.0f, screenSize.width, screenSize.height) ); pRT-&gt;DrawText( log, ARRAYSIZE(log) - 1, pTextFormat, D2D1::RectF(0, rTSize.height - ((nLogLines*textSize)+textSize) , rTSize.width, rTSize.height), pWhiteBrush ); pRT-&gt;EndDraw(); } </code></pre> <p>For some reason, in the OnRender function, nLogLines' value is 0. What is wrong?</p>