#endif
}
else // the file is not Unicode
{
pText = pBuffer ;
// Allocate memory for possibly converted string.
pConv = malloc (2 * iFileLength + 2) ;
// If the edit control is Unicode, convert ASCII text.
#ifdef UNICODE
MultiByteToWideChar (CP_ACP, 0, pText, -1, (PTSTR) pConv,
iFileLength + 1) ;
// If not, just copy buffer
#else
lstrcpy ((PTSTR) pConv, (PTSTR) pText) ;
#endif
}
SetWindowText (hwndEdit, (PTSTR) pConv) ;
free (pBuffer) ;
free (pConv) ;
return TRUE ;
}
{
DWORD dwBytesWritten ;
HANDLE hFile ;
int iLength ;
PTSTR pstrBuffer ;
WORD wByteOrderMark = 0xFEFF ;
// Open the file, creating it if necessary
if (INVALID_HANDLE_VALUE ==
(hFile = CreateFile (pstrFileName, GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, 0, NULL)))
return FALSE ;
// Get the number of characters in the edit control and allocate
// memory for them.
iLength = GetWindowTextLength (hwndEdit) ;
pstrBuffer = (PTSTR) malloc ((iLength + 1) * sizeof (TCHAR)) ;
if (!pstrBuffer)
{
CloseHandle (hFile) ;
return FALSE ;
}
// If the edit control will return Unicode