Home | Info | Community | Development | myReactOS | Contact Us
[static]
Definition at line 223 of file text.c.
Referenced by WriteText().
{ LPBYTE pBytes = NULL; LPBYTE pAllocBuffer = NULL; DWORD dwPos = 0; DWORD dwByteCount; BYTE buffer[1024]; UINT iCodePage = 0; DWORD dwDummy, i; BOOL bSuccess = FALSE; int iBufferSize, iRequiredBytes; BYTE b; while(dwPos < dwTextLen) { switch(iEncoding) { case ENCODING_UNICODE: pBytes = (LPBYTE) &pszText[dwPos]; dwByteCount = (dwTextLen - dwPos) * sizeof(WCHAR); dwPos = dwTextLen; break; case ENCODING_UNICODE_BE: dwByteCount = (dwTextLen - dwPos) * sizeof(WCHAR); if (dwByteCount > sizeof(buffer)) dwByteCount = sizeof(buffer); memcpy(buffer, &pszText[dwPos], dwByteCount); for (i = 0; i < dwByteCount; i += 2) { b = buffer[i+0]; buffer[i+0] = buffer[i+1]; buffer[i+1] = b; } pBytes = (LPBYTE) &buffer[dwPos]; dwPos += dwByteCount / sizeof(WCHAR); break; case ENCODING_ANSI: case ENCODING_UTF8: if (iEncoding == ENCODING_ANSI) iCodePage = CP_ACP; else if (iEncoding == ENCODING_UTF8) iCodePage = CP_UTF8; iRequiredBytes = WideCharToMultiByte(iCodePage, 0, &pszText[dwPos], dwTextLen - dwPos, NULL, 0, NULL, NULL); if (iRequiredBytes <= 0) { goto done; } else if (iRequiredBytes < sizeof(buffer)) { pBytes = buffer; iBufferSize = sizeof(buffer); } else { pAllocBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(), 0, iRequiredBytes); if (!pAllocBuffer) return FALSE; pBytes = pAllocBuffer; iBufferSize = iRequiredBytes; } dwByteCount = WideCharToMultiByte(iCodePage, 0, &pszText[dwPos], dwTextLen - dwPos, (LPSTR) pBytes, iBufferSize, NULL, NULL); if (!dwByteCount) goto done; dwPos = dwTextLen; break; default: goto done; } if (!WriteFile(hFile, pBytes, dwByteCount, &dwDummy, NULL)) goto done; /* free the buffer, if we have allocated one */ if (pAllocBuffer) { HeapFree(GetProcessHeap(), 0, pAllocBuffer); pAllocBuffer = NULL; } } bSuccess = TRUE; done: if (pAllocBuffer) HeapFree(GetProcessHeap(), 0, pAllocBuffer); return bSuccess; }